CloudLinux.ro
Security

How to set up SSH key authentication

Updated 7/20/2026

SSH keys are a pair of files: one public (on the server) and one private (with you). They are far more secure than passwords and eliminate the risk of brute-force attacks.

1. Generate a key pair (on your computer)

ssh-keygen -t ed25519 -C "[email protected]"

Press Enter for the default location and, optionally, set a passphrase for the key.

2. Copy the public key to the server

ssh-copy-id root@SERVER_IP

Or manually, add it to ~/.ssh/authorized_keys on the server.

3. Test the connection

ssh root@SERVER_IP

You should log in without a password.

4. Disable passwords (once the key works)

In /etc/ssh/sshd_config:

PasswordAuthentication no
systemctl restart ssh

Important

Keep the private key safe and never share it. Continue with disabling root login for extra security.

Put this guide into practice on your own VPS

EU cloud servers, billed hourly, ready in minutes, with one-click installs for dozens of apps.

See pricing

Related tutorials