SSH is a widely-used protocol for interacting with remote servers for administration and file transfer. SSH keys provide a more secure authentication method than passwords. Instead of logging in with a password, you use a cryptographic key pair (public and private keys).
ssh-keygen -t ed25519 -C "your_email@example.com" # or for RSA (if ed25519 not supported) ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
Press Enter to accept the default file location, and optionally set a passphrase.
ssh-keygen -t ed25519 -C "your_email@example.com"ssh-copy-id root@your-vps-ip # Enter your VPS password when prompted
cat ~/.ssh/id_ed25519.pubmkdir -p ~/.sshecho "your-public-key-here" >> ~/.ssh/authorized_keys chmod 600 ~/.ssh/authorized_keys chmod 700 ~/.ssh
Try logging in with your SSH key:
ssh root@your-vps-ipYou should be logged in without entering a password (unless you set a passphrase on your key).
After verifying SSH key login works, you can disable password authentication for better security:
# Edit SSH config nano /etc/ssh/sshd_config # Change these lines: PasswordAuthentication no ChallengeResponseAuthentication no PubkeyAuthentication yes # Restart SSH systemctl restart sshd
Make absolutely sure your SSH key authentication is working before disabling password authentication! Otherwise, you'll lock yourself out and need to use VNC console to regain access.
Check file permissions:
chmod 700 ~/.ssh chmod 600 ~/.ssh/authorized_keys
Check SSH logs on the server:
tail -f /var/log/auth.log # Debian/Ubuntu tail -f /var/log/secure # CentOS/RHEL
Always keep a backup of your private key in a secure location. If you lose it and have disabled password authentication, you'll need to use VNC console to regain access to your VPS.