Skip to main content

Why SSH Keys?

SSH keys are more secure than passwords:
PasswordSSH Key
Can be guessedVirtually uncrackable
Brute-force possibleBrute-force impossible
Must be entered manuallyAutomatic authentication
Can be interceptedPrivate key stays local
After setup, you can connect without entering a password - faster and more secure!

Create SSH Key

Windows 10/11 (PowerShell)

1

Open PowerShell

Press Win + X and select Windows Terminal or PowerShell.
2

Generate SSH Key

ssh-keygen -t ed25519 -C "[email protected]"
ED25519 is the most modern and secure algorithm. If your server doesn’t support it, use RSA:
ssh-keygen -t rsa -b 4096 -C "[email protected]"
3

Confirm Location

Enter file in which to save the key (C:\Users\YourName\.ssh\id_ed25519):
Press Enter for the default location.
4

Set Passphrase (recommended)

Enter passphrase (empty for no passphrase):
A passphrase adds extra protection to your key. You can also press Enter for no passphrase.
5

Copy Public Key

cat ~/.ssh/id_ed25519.pub
Copy the entire output (starts with ssh-ed25519).

PuTTYgen (Alternative)

1

Open PuTTYgen

Install PuTTY and open PuTTYgen.
2

Generate Key

  1. Select EdDSA (or RSA with 4096 bits)
  2. Click Generate
  3. Move your mouse in the empty area for randomness
3

Save Keys

  1. Save private key → Save as .ppk file
  2. Copy the text in the upper field (Public Key)

Add Public Key to Server

Now you need to add your Public Key to the server. The easiest way - works on macOS and Linux:
ssh-copy-id root@YOUR-IP-ADDRESS
You’ll be asked for the password once. After that, the key is set up.

Method 2: Manual Copy

1

Log in with Password

ssh root@YOUR-IP-ADDRESS
2

Create SSH Directory (if needed)

mkdir -p ~/.ssh
chmod 700 ~/.ssh
3

Add Public Key

echo "YOUR-PUBLIC-KEY-HERE" >> ~/.ssh/authorized_keys
chmod 600 ~/.ssh/authorized_keys
Replace YOUR-PUBLIC-KEY-HERE with the copied key (starts with ssh-ed25519 or ssh-rsa).
4

Test Connection

Open a new terminal and connect:
ssh root@YOUR-IP-ADDRESS
If there’s no password prompt, the key works!

Disable Password Login

First test that your SSH key works! Otherwise you’ll lock yourself out.
After successful key setup, you can disable password login:
1

Edit SSH Configuration

nano /etc/ssh/sshd_config
2

Change Settings

Find and change these lines:
PasswordAuthentication no
PubkeyAuthentication yes
Use Ctrl + W in nano to search.
3

Restart SSH Service

systemctl restart sshd
4

Test in New Terminal

Open a new terminal (keep the old one open!) and test:
ssh root@YOUR-IP-ADDRESS
If it works, you can close the old terminal.

Manage Multiple Keys

SSH Config File

For multiple servers with different keys, create ~/.ssh/config:
# RDP.sh Production Server
Host rdp-prod
    HostName 185.193.xxx.xxx
    User root
    IdentityFile ~/.ssh/id_ed25519

# RDP.sh Development Server
Host rdp-dev
    HostName 185.193.yyy.yyy
    User root
    IdentityFile ~/.ssh/id_ed25519_dev
    Port 2222

# Other Provider
Host other-server
    HostName example.com
    User admin
    IdentityFile ~/.ssh/other_key
Now you can simply connect with:
ssh rdp-prod
ssh rdp-dev

Troubleshooting

Possible causes:
  • Public key not copied correctly
  • Wrong permissions on server
  • Wrong key being used
Solution:
# Check permissions on server
chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys

# Check which key is being used
ssh -v root@YOUR-IP
The SSH agent has no key loaded.Solution:
ssh-add ~/.ssh/id_ed25519
Check on server:
cat ~/.ssh/authorized_keys
The key must be on a single line and start with ssh-ed25519 or ssh-rsa.
Unfortunately, the passphrase cannot be recovered.Solution:
  1. Generate a new key
  2. Add the new public key to the server
  3. 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.

Next Steps