Why SSH Keys?
SSH keys are more secure than passwords:| Password | SSH Key |
|---|---|
| Can be guessed | Virtually uncrackable |
| Brute-force possible | Brute-force impossible |
| Must be entered manually | Automatic authentication |
| Can be intercepted | Private key stays local |
Create SSH Key
- Windows
- macOS
- Linux
Windows 10/11 (PowerShell)
Generate SSH Key
ED25519 is the most modern and secure algorithm. If your server doesn’t support it, use RSA:
Set Passphrase (recommended)
PuTTYgen (Alternative)
Open PuTTYgen
Install PuTTY and open PuTTYgen.
Generate Key
- Select EdDSA (or RSA with 4096 bits)
- Click Generate
- Move your mouse in the empty area for randomness
Add Public Key to Server
Now you need to add your Public Key to the server.Method 1: ssh-copy-id (recommended)
The easiest way - works on macOS and Linux:Method 2: Manual Copy
Add Public Key
YOUR-PUBLIC-KEY-HERE with the copied key (starts with ssh-ed25519 or ssh-rsa).Disable Password Login
After successful key setup, you can disable password login:Manage Multiple Keys
SSH Config File
For multiple servers with different keys, create~/.ssh/config:
Troubleshooting
Permission denied (publickey)
Permission denied (publickey)
Possible causes:
- Public key not copied correctly
- Wrong permissions on server
- Wrong key being used
Agent has no identities
Agent has no identities
The SSH agent has no key loaded.Solution:
Key not accepted
Key not accepted
Check on server:The key must be on a single line and start with
ssh-ed25519 or ssh-rsa.Forgot passphrase
Forgot passphrase
Unfortunately, the passphrase cannot be recovered.Solution:
- Generate a new key
- Add the new public key to the server
- Delete the old key
Best Practices
🔐 Use a Passphrase
A passphrase protects your key if someone gains access to your computer.
🔄 Rotate Keys
Regularly create new keys and remove old ones from authorized_keys.
💾 Backup
Back up your private key in a secure location. Without it, you’ll lose access!
🚫 Never Share
Never share your private key. Only the public key is copied to servers.