🔑 How To Set Up SSH Keys on Ubuntu 20.04
SSH keys provide a secure way to log into your server without a password. This guide covers creating an SSH key pair and configuring key-based authentication.
1Generate SSH Key Pair
On your LOCAL machine:
ssh-keygen
Press Enter to accept the default location. Optionally set a passphrase.
2Copy Public Key to Server
Using ssh-copy-id:
ssh-copy-id username@remote_host
Alternative method:
cat ~/.ssh/id_rsa.pub | ssh username@remote_host "mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys"
3Test SSH Key Login
ssh username@remote_host
✅ If you connect without a password prompt, SSH key authentication is working!
4Disable Password Authentication
⚠️ Only do this after confirming SSH key login works!
Edit the SSH configuration:
sudo nano /etc/ssh/sshd_config
Set these options:
PasswordAuthentication no
PubkeyAuthentication yes
Restart SSH:
sudo systemctl restart ssh
🎉 Your server now uses secure SSH key authentication!