Engineering notes

VPS SSH key authentication done properly

Set up VPS SSH key authentication, disable password logins safely, manage authorised keys and retain console access when a configuration change goes wrong.

By Vozora · Published

VPS SSH key authentication done properly

A password prompt on an internet-facing server is not a convenience feature. It is an endpoint that will receive automated guesses for as long as the VPS exists. VPS SSH key authentication replaces that guessable secret with a cryptographic proof held on your machine. Set it up carefully and SSH becomes both safer and less tedious. Set it up carelessly and you can lock yourself out of the server you are trying to secure.

This is a practical configuration for a self-managed Linux VPS. It assumes you can reach the server over SSH already and have a recovery route available, such as a serial or VNC console. Keep your existing SSH session open until you have tested every change from a second terminal.

How VPS SSH key authentication works

An SSH key pair contains a private key and a public key. The private key stays on your workstation. The public key is copied to the server, normally into ~/.ssh/authorized_keys for the Linux login user.

When you connect, the server sends data that can only be signed by the corresponding private key. The server verifies that signature against the public key it holds. Your private key never crosses the network, and neither does a reusable password.

This does not make the server immune to compromise. A stolen private key, an infected development machine, a badly managed CI secret, or a user with overly broad sudo access can still cause damage. Keys remove one common attack path. They do not replace patching, backups, least privilege or sensible application security.

Generate a key on the machine you trust

Generate keys on the workstation from which you will administer the VPS, not on the VPS itself. On current Linux, macOS and Windows OpenSSH installations, Ed25519 is usually the right default:

ssh-keygen -t ed25519 -a 100 -C "your-name@workstation"

Accept the default location unless you have a reason to keep a separate key directory. Set a passphrase when prompted. A passphrase protects the private key if someone copies the file from your laptop or its backups. It is a small cost for an administrator key that can access production systems.

The command creates two files, typically ~/.ssh/id_ed25519 and ~/.ssh/id_ed25519.pub. The .pub file is the public half. It is safe to place on servers. The file without .pub is private. Do not paste it into a ticket, commit it to a repository, or put it in a shell script.

For automated jobs, use a separate key with the narrowest practical permissions. Do not reuse your personal administrator key in CI. Separation makes revocation possible without disrupting every other access path.

Hardware-backed keys are worth considering

If you administer valuable systems from several devices, a hardware-backed FIDO2 SSH key can reduce the risk of private-key extraction. OpenSSH supports ed25519-sk keys on compatible hardware. The trade-off is operational: recovery and replacement need planning, and unattended automation cannot touch a physical key. For most small VPS deployments, a passphrase-protected Ed25519 key plus a well-secured workstation is a good baseline.

Install the public key without breaking access

If password login is currently enabled, ssh-copy-id is the simplest option:

ssh-copy-id -i ~/.ssh/id_ed25519.pub image-user@server-ip

Replace image-user with the user supplied by your Linux image. Many images deliberately do not permit direct root login. SSH in as that image user, then use sudo for administration. This gives you an audit trail in logs and avoids making the root account the first target for every scan.

If ssh-copy-id is unavailable, append the public-key contents manually while logged in as the target user:

mkdir -p ~/.ssh chmod 700 ~/.ssh printf '%s\n' 'PASTE_PUBLIC_KEY_HERE' >> ~/.ssh/authorized_keys chmod 600 ~/.ssh/authorized_keys

Ownership matters as much as mode. The .ssh directory and authorized_keys file should belong to the login user, not root. On a typical system, verify this with:

ls -ld ~/.ssh ls -l ~/.ssh/authorized_keys

SSH may reject keys when the home directory, .ssh directory or authorized_keys file is writable by other users. Do not work around this by weakening SSH checks. Correct the ownership and permissions instead.

Now open a second terminal and test the key explicitly:

ssh -i ~/.ssh/id_ed25519 image-user@server-ip

You should get a shell without entering the account password. If your key has a passphrase, your local SSH agent may request it once. Only proceed after this second connection works and sudo -v succeeds where you need administrative access.

Disable passwords only after the test succeeds

Password authentication is often enabled initially so that a new server remains accessible during provisioning. Once a verified key works, disable it in the SSH daemon configuration. Create a small drop-in rather than editing a large vendor-supplied file where your distribution supports it:

sudoedit /etc/ssh/sshd_config.d/99-local-auth.conf

Add:

PasswordAuthentication no KbdInteractiveAuthentication no PermitRootLogin no PubkeyAuthentication yes

KbdInteractiveAuthentication no matters because some PAM-backed authentication flows can otherwise still present a password-style prompt. PermitRootLogin no is appropriate when you log in as a normal image user and escalate with sudo.

Before reloading the service, validate the complete configuration:

sudo sshd -t sudo systemctl reload ssh

The test command should return no output. If it reports an error, fix that error before reloading. Then make another new SSH connection. Keep the original session alive until you have confirmed that password login is refused and key login still works.

On distributions that do not load /etc/ssh/sshd_config.d/ by default, place the settings in /etc/ssh/sshd_config instead. Check the active values rather than assuming the file order:

sudo sshd -T | grep -E 'passwordauthentication|kbdinteractiveauthentication|permitrootlogin|pubkeyauthentication'

Configuration precedence differs across images, and an existing setting later in a file can override an earlier one. The running daemon's effective configuration is the fact that matters.

Manage keys as access records, not permanent clutter

Every line in authorized_keys is an access grant. Give each person and each device its own key line with a useful comment, such as alex-laptop-2026 or deploy-ci-production. Do not share one private key across a team simply because it is quick.

When a contractor leaves, a laptop is lost, or an automation credential is replaced, remove the relevant public-key line and test that other administrators still have access. This is much cleaner than changing a shared password and trying to discover every service that used it.

For a small team, review authorised keys during routine maintenance. For larger estates, configuration management or an identity-aware access system may be a better fit. It depends on the number of hosts, the rate of staff change and whether you need central audit controls. Hand-editing keys is reasonable for a few servers; it becomes error-prone when repeated across dozens.

Avoid copying the same key into every environment. Separate development, staging and production keys limit the blast radius of a compromised workstation. You can also add restrictions to keys used by automation, including a forced command or source-IP restriction, but test them carefully. Restrictions that look harmless can break deployment tooling in ways that are difficult to diagnose.

Plan for the lockout you hope never to need

Firewall rules, SSH configuration changes and an accidentally removed key can all cut off network access. A recovery console is not a substitute for careful testing, but it is the right fallback when the network path is unavailable. Vozora VPS instances include a browser console for this reason. Servers have no password by default, so the browser console can only log in if you have set one.

Use the console to inspect /var/log/auth.log or the system journal, repair authorized_keys, undo a faulty SSH configuration and validate it with sshd -t. Treat console credentials and control-panel access with the same care as root access. If an attacker can provision consoles or reset access, SSH key hygiene alone will not protect the server.

Store an encrypted backup of important private keys or document a recovery process that does not depend on one employee's laptop. The better option for teams is usually multiple individual administrator keys, not a single emergency key copied widely. You need continuity, but you also need to know who can enter.

A working SSH key is not the end state. It is the foundation for a server you can administer predictably: individual access, no password guessing, tested recovery and configuration changes made one reversible step at a time.

© 2026 Vozora. A trading name of Bankside Technology Ltd, registered in England and Wales, company no. 17253446. Registered office: First Floor, Swan Buildings, 20 Swan Street, Manchester, England, M4 5JW.