In this guide: SSH keys vs passwords for secure server access: how SSH authentication works, generating keys, adding them to your server, disabling password login, and…
If you connect to a VPS or hosting account via SSH with a password, your server is exposed to constant brute-force attempts. SSH keys are a much more secure and convenient alternative — and they take only a few minutes to set up.
Password authentication:
You type a password; the server checks it. Anyone who guesses or steals the password can log in. Bots constantly try common passwords against SSH servers.
Key-based authentication:
You create a key pair:
~/.ssh/authorized_keys.When you connect, the server uses your public key to create a challenge that only your private key can answer correctly. The private key never leaves your computer.
Benefits:
On macOS, Linux, or Windows 10/11 (PowerShell or Windows Terminal include OpenSSH):
ssh-keygen -t ed25519 -C "your-email@example.com"
ssh-keygen -t rsa -b 4096.)~/.ssh/id_ed25519).You now have:
~/.ssh/id_ed25519 → private key (keep secret)~/.ssh/id_ed25519.pub → public key (safe to share)Use an SSH agent so you enter the passphrase once per session:
ssh-add ~/.ssh/id_ed25519
Password managers like 1Password and some others can also store SSH keys and act as an SSH agent.
Option 1 — ssh-copy-id (Mac/Linux):
ssh-copy-id -i ~/.ssh/id_ed25519.pub user@your-server.com
Option 2 — Manually:
id_ed25519.pub.bash
mkdir -p ~/.ssh && chmod 700 ~/.ssh
nano ~/.ssh/authorized_keys # paste the key on a new line
chmod 600 ~/.ssh/authorized_keysOption 3 — Hosting control panel:
cPanel (“SSH Access → Manage SSH Keys → Import Key”), hPanel, Plesk, and cloud providers (when creating a VPS) let you add public keys through the dashboard.
Test the connection in a new terminal window:
ssh user@your-server.com
You should connect without a password prompt (other than your key passphrase if not using an agent).
Once key login works, disable passwords on your VPS:
bash
sudo nano /etc/ssh/sshd_configPasswordAuthentication no
PermitRootLogin prohibit-passwordPermitRootLogin no if you use a separate sudo user — recommended.)/etc/ssh/sshd_config.d/ — check those files too.bash
sudo systemctl restart ssh # or sshd, depending on the systemAdditional hardening:
On shared hosting, you typically can’t change server-wide SSH settings, but you can still use keys for your account.
authorized_keys regularly and remove unknown or old keys.~/.ssh/config.Example ~/.ssh/config:
Host myserver
HostName your-server.com
User deploy
IdentityFile ~/.ssh/id_ed25519
Now connect with just ssh myserver. New to the command line? See Terminal Basics Every Website Owner Should Know.
Further reading: OWASP Top 10 web security risks
ssh-copy-id, manually, or your control panel.We may earn a commission on purchases made through these links, at no extra cost to you.
Don’t miss the chance to participate in the biggest giveaway of this year.