SSH keys allow passwordless server login and improve security. Below: how to generate a key, add it to the server, and disable password login.
Applies to:
✔ VPS
✔ Dedicated servers
✔ Linux, macOS, Windows
ssh-keygen -t ed25519 -C "your@email.com"
Or RSA:
ssh-keygen -t rsa -b 4096
ssh-keygen -t ed25519
ssh-copy-id -i ~/.ssh/id_ed25519.pub root@SERVER_IP
cat ~/.ssh/id_ed25519.pub
mkdir -p /root/.ssh
echo "PUBLIC_KEY_CONTENT" >> /root/.ssh/authorized_keys
chmod 700 /root/.ssh
chmod 600 /root/.ssh/authorized_keys
Edit authorized_keys on the server and remove the line with the unwanted key:
nano /root/.ssh/authorized_keys
Before disabling passwords, make sure key-based login works! Otherwise you'll lose server access.
In /etc/ssh/sshd_config:
PasswordAuthentication no
PubkeyAuthentication yes
systemctl restart sshd
ssh root@SERVER_IP
Should connect without a password prompt.
If key login doesn't work, check permissions on ~/.ssh (700) and authorized_keys (600). If locked out, connect via VNC/IPMI console.