SSH Key Authentication for Linux Servers: A Practical Setup Checklist
SSH gives administrators a secure way to manage a Linux web server remotely. A password can work, but it is easy to reuse, guess or expose through phishing. SSH key authentication replaces the account password at login with a cryptographic key pair. The private key stays on your device; the public key is installed on the server. Here is a practical setup checklist that reduces risk without accidentally locking you out.
Understand What the Two Keys Do
When you connect, the server checks that your client controls the private key corresponding to an authorised public key. The private key is never copied to the server. This does not make the server automatically secure: an infected laptop or a stolen, unprotected private key can still give an attacker access. Use a passphrase and keep the device itself protected.
Generate a Dedicated Key Pair
On your own computer, run ssh-keygen -t ed25519 -C "your-name@your-device". Accept a dedicated file path if you manage multiple servers, and choose a strong passphrase. The command creates a private key and a matching .pub file. Share only the public key. Never paste the private key into a ticket, email or web control panel.
Keep a recoverable backup of the private key in an encrypted location you control. A password manager that supports files or an encrypted backup drive can help. Record which public key belongs to which administrator so you can remove access cleanly later.
Install the Public Key and Test It
While password login still works, use ssh-copy-id -i ~/.ssh/id_ed25519.pub user@server to append your public key to the account’s ~/.ssh/authorized_keys. If you use a custom key filename, substitute its path. On systems without ssh-copy-id, install the public key manually, taking care not to overwrite other administrators’ entries.
Open a second terminal and test ssh -i ~/.ssh/id_ed25519 user@server. Leave the original working session open until the new login succeeds. If authentication fails, check ownership and permissions on the home directory, ~/.ssh and authorized_keys. Our guide to Linux file permissions explains why overly open files can cause trouble.
Harden Access Without Losing Recovery
Only after key login works for every required administrator should you consider disabling password authentication in the SSH server configuration. Keep a verified provider console or other recovery route available first. Apply changes carefully, validate the configuration, and test another new session before closing existing connections. If the service fails to reload, our systemd troubleshooting checklist can help you inspect service status and logs.
When a client first connects, verify the server’s host-key fingerprint through a trusted channel rather than blindly accepting an unexpected identity. SSH keys authenticate users, while host-key checking helps confirm that you reached the intended server.
Review and Revoke Access
Give each person their own key; do not share a single private key across a team. Review authorized_keys after staff changes, remove obsolete entries, and investigate unfamiliar login attempts in SSH logs. Rotation is especially important if a device is lost or a private key may have been exposed. The goal is a small, auditable set of authorised keys and a tested recovery path—not a configuration change that nobody can safely undo.
For command examples and configuration details, see the official Ubuntu OpenSSH server guide.