Lost SSH key access
If your private key is gone, try any other device or user that still has a working key first. If none exists, a root password reset helps only when sshd allows password logins; otherwise open a support ticket, restore a backup, or rebuild. Once you are back in, keep two keys from two devices so this never happens again.
Recovery and troubleshooting guide, updated 2026-12-03
Which way back in should you try first?
Go through these in order, from least to most disruptive:
- Another device that already has a key for this server: a second laptop, a desktop, a phone app, a CI system. Look for a matching entry in that device's
~/.ssh/config. - Another user account with its own key and sudo rights. Log in as that user and fix root from there.
- Root password reset in the console, if sshd still allows password logins for root. See reset the root password.
- A support ticket: describe what you lost and what you tried. Support can tell you what is possible for your case.
- Restore a backup from the add-on to the last day your key was still installed, or to a day before a bad change.
- Rebuild with your new key selected. It wipes the disk and keeps the IP, so do it only when the data is safe elsewhere.
Before any of this, check you really lost the key. Search for it with ls -la ~/.ssh, look in old backups of your home folder, and check whether your SSH agent still holds it with ssh-add -L, which prints public keys for every loaded private key. An agent that still has it can even push a new key for you.
What if the key is still loaded in your agent?
A key loaded with ssh-add stays in memory until you log out or reboot. Even if the file is deleted, the agent can still sign logins. Use that window: log in, add a new public key, and test it.
ssh-add -L
ssh root@203.0.113.10
# on the server, append your new public key:
echo "ssh-ed25519 AAAAC3...new laptop-2026-12" >> /root/.ssh/authorized_keysDo not close the session until a login with the new key works from a second terminal.
How does authorized_keys work?
Each user has a file at ~/.ssh/authorized_keys: for root that is /root/.ssh/authorized_keys, for a user named deploy it is /home/deploy/.ssh/authorized_keys. Each line is one public key: a type such as ssh-ed25519, the base64 key, and an optional comment. sshd lets you in when your client proves it holds the private half of any line.
Keys you save in the console are written to root at creation or rebuild only. A key added in the console later does not appear on a running server by itself, so you add it to the file by hand. Edit with care: a single line broken in two invalidates that key. Prefer appending with >> or using ssh-copy-id from your computer while a login still works:
ssh-copy-id -i ~/.ssh/newkey.pub root@203.0.113.10Which permissions does sshd insist on?
With the default StrictModes yes, sshd ignores keys if the home folder, the .ssh folder or the file can be written by other users. Set them like this, using the right owner:
chown -R deploy:deploy /home/deploy/.ssh
chmod 700 /home/deploy/.ssh
chmod 600 /home/deploy/.ssh/authorized_keys
chmod go-w /home/deployOn Rocky Linux and AlmaLinux, SELinux also checks the file label. If you created the folder with unusual tools or copied it from elsewhere, restore labels with restorecon -Rv /home/deploy/.ssh. A key that works on Ubuntu but fails on Rocky with no clear error is usually this.
When a key is refused, the server log says why: journalctl -u ssh -n 30 on Ubuntu and Debian, journalctl -u sshd -n 30 on the dnf family. Lines such as Authentication refused: bad ownership or modes point straight at the fix.
How do you replace a lost or leaked key cleanly?
A lost laptop means the private key may be in someone else's hands. Removing its line from every server is as important as adding the new one.
- Generate a new key on a device you control:
ssh-keygen -t ed25519 -a 100 -C "desk-2026-12". - Add the new public key to
authorized_keysfor each user who needs it, and to the console SSH keys page for future servers. - Test the new key from a second terminal.
- Remove the old line. The comment at the end of each line tells you which device it belonged to, which is why good comments matter.
- Remove the old key from the console SSH keys page too, so it is not ticked by accident on a new order.
To find the fingerprint of each line on the server, run ssh-keygen -lf /root/.ssh/authorized_keys. Compare it with ssh-keygen -lf ~/.ssh/key.pub on your devices to know which line is which.
Why keep two keys and two users?
One key is one point of failure. Two keys from two devices, or one normal key plus a hardware security key, means a lost laptop is an inconvenience, not an outage. OpenSSH supports hardware keys with ssh-keygen -t ed25519-sk, which keep the private part on the device.
A second user with sudo rights protects against mistakes in root's own setup, such as a broken shell or a bad edit to /root/.ssh. Create it once, as described in the hardening guide, and test both paths every few months.
How do you rotate keys on a schedule?
Rotation means replacing keys before they become a risk, not after. A simple rhythm for a small team:
- Once a year, or when someone leaves, each person creates a new key.
- Add all new keys everywhere, test, then remove all old keys in one sweep.
- Keep a short inventory: which public key, whose device, which servers.
For many servers, keep one source of truth such as a file in your configuration repository, and deploy authorized_keys from it with a small script or a configuration tool. That way removing a person means deleting one line and running one command.
What if nothing works?
When no key, user or password gets you in, the data is still on the disk, but you cannot reach it from inside. Open a ticket first; describe the situation and ask what support can do. If you have the backup add-on, a restore to an earlier day brings back the old authorized_keys, which helps only if you still hold one of those keys. If none of that applies, rebuild with your new key selected and restore your data from your own off-server backups. Next time the second key and the second user make all of this unnecessary.
Questions about this guide
Does a key added in the console reach my running server?
No. Console keys are installed at creation and rebuild. For a running server, append the public line to ~/.ssh/authorized_keys yourself.
Can I recover a private key from the public key?
No, that is the point of public key cryptography. Look for copies of the private file or a loaded agent instead.
Why does my new key work for root but not for my user?
Usually permissions or ownership on the user's .ssh folder. Check the sshd journal for "bad ownership or modes".
Should I protect keys with a passphrase?
Yes. A passphrase protects the file if a device is stolen; ssh-add means you type it once per session.
Can I use the same key on every server?
You can, and many people do. Two keys from two devices, both on every server, is the sensible minimum.
Will a rebuild keep my keys?
A rebuild installs the keys you tick on the rebuild form and wipes everything else on the disk.