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
- Generate a key pair with
ssh-keygen -t ed25519 -C "you@example.com"and set a passphrase. - Load it into
ssh-agentso you type the passphrase once per session. - Copy the public key (
.pub) to the server withssh-copy-idor into~/.ssh/authorized_keys. - Check permissions:
700on~/.ssh,600onauthorized_keys. - Test a key login in a second terminal.
- Only then disable password login on the server.
- 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:
| File | What it is | Share it? |
|---|---|---|
~/.ssh/id_ed25519 | Private key | Never |
~/.ssh/id_ed25519.pub | Public key | Yes, 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.
- Copy the whole line from your
.pubfile. - On GitHub, open your profile picture menu, then Settings, then SSH and GPG keys.
- 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.
- 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 typingyes. 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 )
- GitHub Docs: Generating a new SSH key and adding it to the ssh-agent
- GitHub Docs: Adding a new SSH key to your GitHub account
- OpenBSD manual pages: ssh-keygen(1)
- OpenBSD manual pages: sshd(8): AUTHORIZED_KEYS file format
- OpenBSD manual pages: sshd_config(5)