Talk to the NOC, IST hours — +91 75994 50220 support@bigdomainhost.com
Guide

What an SSH key is and how to set up SSH keys safely

An SSH key replaces your server password with a key pair that cannot be guessed. This guide shows how to create one on any computer, put it on a server and GitHub, and then switch passwords off.

Short answer: An SSH key is a pair of files used to log in over SSH without a password: a private key that stays on your computer and a public key you copy to servers and GitHub. Create one with ssh-keygen -t ed25519, protect it with a passphrase, add the .pub file to authorized_keys, test the login, then disable password authentication.

What is an SSH key?

An SSH key is a pair of matching files that lets you log in to a server without typing a password. The private key stays on your own computer and works like a password that never leaves it. The public key is copied to every server or service you want to reach, and it is safe to share. When you connect, your computer uses the private key to sign data unique to that session, and the server checks the signature against the public key. Only the holder of the private key can produce it, and nothing secret crosses the network.

That is why key login is safer than a password. A password can be guessed, reused or phished, and bots try huge numbers of them against any server on the internet. A modern key cannot realistically be guessed, and the server never sees your private key, so a compromised server cannot leak it.

SSH key setup: quick checklist

  1. Generate a key pair with ssh-keygen -t ed25519 -C "you@example.com" and set a passphrase.
  2. Load it into ssh-agent so you type the passphrase once per session.
  3. Copy the public key (.pub) to the server with ssh-copy-id or into ~/.ssh/authorized_keys.
  4. Check permissions: 700 on ~/.ssh, 600 on authorized_keys.
  5. Test a key login in a second terminal.
  6. Only then disable password login on the server.
  7. Add the same public key to GitHub if you push code over SSH.

How to generate an SSH key

The same ssh-keygen command works on Linux, macOS and Windows 10 and 11, because all three ship the OpenSSH client. Ed25519 is the key type to choose today: the keys are short, fast and strong.

ssh-keygen -t ed25519 -C "you@example.com"

The -C value is only a comment to help you recognise the key later; an email address or a label such as laptop-2026 both work. Press Enter to accept the default file, then type a passphrase. If ssh-keygen warns that the file already exists and asks Overwrite (y/n)?, answer n: overwriting destroys your existing key and locks you out of every server that trusts it. Give the new key a different name with -f ~/.ssh/id_ed25519_new instead. You end up with two files:

FileWhat it isShare it?
~/.ssh/id_ed25519Private keyNever
~/.ssh/id_ed25519.pubPublic keyYes, with servers and GitHub

If an old server or device does not accept Ed25519, create an RSA key of 4096 bits instead:

ssh-keygen -t rsa -b 4096 -C "you@example.com"

How to create an SSH key on Linux and macOS

Open Terminal and run the command above. To print the public key so you can copy it, run cat ~/.ssh/id_ed25519.pub. It is one long line starting with ssh-ed25519.

How to create an SSH key on Windows 10 and 11

Windows 10 (version 1809 onwards) and Windows 11 include the OpenSSH client, so you do not need PuTTY. Open PowerShell and run the same ssh-keygen -t ed25519 command. The files are saved in C:\Users\you\.ssh\. Show the public key with:

Get-Content $env:USERPROFILE\.ssh\id_ed25519.pub

If PowerShell says ssh-keygen is not recognised, add OpenSSH Client under Settings, Optional features.

Passphrases and ssh-agent

A passphrase encrypts the private key file, so a stolen laptop or a leaked backup does not hand over your servers. To avoid typing it for every connection, load the key into ssh-agent, which holds it in memory.

On Linux:

eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_ed25519

On macOS, add this to ~/.ssh/config so the passphrase is kept in the Keychain:

Host *
  AddKeysToAgent yes
  UseKeychain yes
  IdentityFile ~/.ssh/id_ed25519

then run ssh-add --apple-use-keychain ~/.ssh/id_ed25519 (macOS 12 Monterey and later; older versions use ssh-add -K). UseKeychain only exists in Apple's OpenSSH, so do not copy this block to a Linux machine's config. On Windows the agent service is disabled by default. In PowerShell opened as Administrator:

Get-Service ssh-agent | Set-Service -StartupType Automatic
Start-Service ssh-agent

Then, in a normal PowerShell window, run ssh-add $env:USERPROFILE\.ssh\id_ed25519.

How to set up SSH keys on a server

The server needs your public key in the ~/.ssh/authorized_keys file of the account you log in as. On Linux and macOS, ssh-copy-id does this for you, using your password one last time:

ssh-copy-id -i ~/.ssh/id_ed25519.pub deploy@203.0.113.10

Windows has no ssh-copy-id. From PowerShell, pipe the key over SSH instead:

Get-Content $env:USERPROFILE\.ssh\id_ed25519.pub | ssh deploy@203.0.113.10 "mkdir -p ~/.ssh && chmod 700 ~/.ssh && cat >> ~/.ssh/authorized_keys && chmod 600 ~/.ssh/authorized_keys"

Adding the key by hand

If you are already on the server, paste the key on its own line into authorized_keys and set the permissions. OpenSSH refuses keys when these files are writable by other users:

mkdir -p ~/.ssh
nano ~/.ssh/authorized_keys
chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys

The files must also be owned by that user. If you created them as root for another account, fix it with chown -R deploy:deploy /home/deploy/.ssh. Now test from a new terminal with ssh deploy@203.0.113.10. You should get in without a password prompt, or with only your key passphrase. If the connection itself fails, see SSH connection refused: causes and fixes.

How to add an SSH key to GitHub

GitHub uses the same public key to authorise git push and git pull over SSH.

  1. Copy the whole line from your .pub file.
  2. On GitHub, open your profile picture menu, then Settings, then SSH and GPG keys.
  3. Click New SSH key, give it a title such as the computer's name, keep the type as authentication key, paste the key and save.
  4. Test with ssh -T git@github.com. On the first connection SSH shows GitHub's host key fingerprint; compare it with the fingerprints GitHub publishes in its docs before typing yes. A greeting with your username means it works.

Use the SSH clone address (git@github.com:user/repo.git) rather than the HTTPS one. An HTTPS remote does not use your SSH key at all and asks for a personal access token instead. To switch an existing clone, run git remote set-url origin git@github.com:user/repo.git.

Disable password login after testing

Bots can still guess passwords until password login is switched off. Keep your current session open, confirm a key login works from a second terminal, then create /etc/ssh/sshd_config.d/00-keys-only.conf:

PasswordAuthentication no
KbdInteractiveAuthentication no

This works because Ubuntu 20.04 and later read /etc/ssh/sshd_config.d/*.conf from the top of sshd_config, and sshd uses the first value it finds for each setting. The 00- prefix makes this file win over others such as 50-cloud-init.conf, which some cloud images use to set PasswordAuthentication yes. If your sshd_config has no Include line, put the two settings in sshd_config itself. On OpenSSH older than 8.7 the second setting is called ChallengeResponseAuthentication.

Check and apply it:

sudo sshd -t
sudo systemctl restart ssh
sudo sshd -T | grep -Ei 'passwordauthentication|kbdinteractiveauthentication'

Both lines should end in no. If sshd -t prints an error, fix it before restarting, or the service may not come back up.

On Red Hat-based systems the service is called sshd. The full hardening sequence, including root login and the firewall, is in Ubuntu VPS initial setup.

Rotating and removing SSH keys

Treat keys like any other credential. Use one key per device, so losing a laptop means removing one line, not replacing every key you own. To retire a key, delete its line from ~/.ssh/authorized_keys on each server and remove it under SSH and GPG keys on GitHub. The comment at the end of each line tells you which device it belongs to. To rotate, generate a new key, add it everywhere, test it, and only then remove the old one. To change only the passphrase, run ssh-keygen -p -f ~/.ssh/id_ed25519.

Using SSH keys on Bigdomainhost

When you order a Bigdomainhost KVM VPS, you can paste your SSH public key at order time. The VPS quickstart notes that this disables password login from the first boot, so you log in as root with your key straight away and skip the password stage entirely. Servers run in data centres in Mumbai (BOM-1) and Delhi NCR (DEL-1).

If a key or SSH change locks you out, the out-of-band console in the control panel still lets you in to fix authorized_keys. For help, call +91 75994 50220 during IST hours, WhatsApp the same number at any time, or email support@bigdomainhost.com.

Sources (checked )

Answers

Frequently asked questions

Still unsure? Call +91 75994 50220 or write to support@bigdomainhost.com — a human replies in IST hours.

What is an SSH key?

An SSH key is a pair of linked files used to prove who you are to an SSH server. The private key stays on your computer and must never be shared. The public key is copied to servers and services such as GitHub. The server checks that you hold the matching private key, so no password is sent.

How do I generate an SSH key?

Open Terminal on Linux or macOS, or PowerShell on Windows 10 or 11, and run ssh-keygen -t ed25519 -C followed by an email or label in quotes. Accept the default file location (but do not overwrite an existing key) and set a passphrase. If an older system rejects Ed25519, use ssh-keygen -t rsa -b 4096 instead.

How do I add an SSH key to GitHub?

Copy the contents of your .pub file, then on GitHub go to Settings, SSH and GPG keys, and click New SSH key. Give it a title, paste the key and save. Test with ssh -T git@github.com, and use the SSH clone address for your repositories so Git uses the key.

Is an SSH key safer than a password?

Yes. A password can be guessed, reused or phished, and bots attack SSH passwords constantly. A private key is far too long to guess and never leaves your computer during login. Bots can still guess passwords until password authentication is disabled on the server, so turn it off after testing your key.

Why is my SSH key not working on the server?

The usual causes are wrong permissions or ownership. The .ssh folder must be 700 and authorized_keys 600, both owned by the login user. Also check the key is pasted as one unbroken line, that you are logging in as the right user, and run ssh -v to see which keys are being offered.

Support that picks up the phone.

In IST hours, in Hindi or English, and WhatsApp replies fastest at any time. Sales, migration and emergencies all reach the same engineers. No offshore queue, no 48-hour first reply.

Need cPanel or WHM with the ports already sorted?

Web & cPanel hosting comes with cPanel ready to log in to, reseller hosting adds white-label WHM, and a KVM VPS can have cPanel & WHM pre-installed. Call +91 75994 50220 or email support@bigdomainhost.com.