user@your.server: Permission denied (publickey). SSH tried key authentication, the server said no, and there was nothing else to try. The message never says why, so people start regenerating keys at random. Don't. It's almost always one of seven things, and two commands tell you which.
First: get the real reason
On your machine, run SSH in verbose mode:
ssh -v user@your.server Look for lines like Offering public key: /home/you/.ssh/id_ed25519 and Authentications that can continue: publickey. They show which keys your client tried.
If you still have another way in (a console in your provider's dashboard, or a second session), watch the server side at the same time:
sudo journalctl -u ssh -f # Ubuntu, Debian sudo journalctl -u sshd -f # RHEL family The server log often says exactly what's wrong: bad ownership, an invalid user, or a key type it won't accept.
1. Wrong user name
Cloud images often disable root login and create a default user instead: ubuntu on Ubuntu, debian on Debian, ec2-user on Amazon Linux. Others do the opposite and only set up root. Use the user your provider documents, or the one you created:
ssh ubuntu@your.server 2. Your client isn't offering the right key
If ssh -v never offers the key that's on the server, point at it directly:
ssh -i ~/.ssh/id_ed25519 user@your.server Then make it permanent in ~/.ssh/config:
Host myserver HostName your.server User deploy IdentityFile ~/.ssh/id_ed25519 IdentitiesOnly yes IdentitiesOnly yes matters if you have many keys loaded in an agent. Without it, the client may offer five wrong keys first and hit the server's MaxAuthTries limit ("Too many authentication failures") before it gets to the right one.
3. The public key isn't on the server
The public key (id_ed25519.pub, one line) must be in ~/.ssh/authorized_keys of the user you log in as. The common mistakes are adding it to root's file while logging in as another user, or pasting it with line breaks in the middle.
From a machine that can still log in, ssh-copy-id does it correctly:
ssh-copy-id -i ~/.ssh/id_ed25519.pub user@your.server 4. Permissions on the server
sshd refuses keys if the files around them are too open. This is the StrictModes check, and it's on by default.
chmod 700 ~/.ssh chmod 600 ~/.ssh/authorized_keys chown -R $USER:$USER ~/.ssh chmod go-w ~ That last line matters too: if the home directory itself is writable by group or others, the key is refused.
5. Permissions on your private key
If your client prints WARNING: UNPROTECTED PRIVATE KEY FILE!, it ignores the key. Fix it locally:
chmod 600 ~/.ssh/id_ed25519 6. The server config says no
Check the settings sshd is actually using, not just what's in one file:
sudo sshd -T | grep -Ei 'pubkeyauthentication|allowusers|authorizedkeysfile|permitrootlogin' AllowUsers that doesn't include your user, PermitRootLogin no when you log in as root, or a custom AuthorizedKeysFile path are all common causes after someone hardened the server. Drop-in files in /etc/ssh/sshd_config.d/ count too.
7. An old RSA key
Newer OpenSSH versions disabled the old ssh-rsa signature algorithm (RSA with SHA-1) by default. Very old clients, or old keys used by old tools, can be refused even though the key is in the right place. The clean fix is a modern key:
ssh-keygen -t ed25519 -C "you@example.com" Then add the new .pub to the server.
Don't lock yourself out
When you change SSH settings or keys, keep your current session open and test the new login in a second terminal. Most providers also have a browser console that works without SSH, so find it before you need it.
Checklist
-
ssh -v: which keys were offered? -
journalctl -u ssh -fon the server: what did it say? - Right user name for the image
-
-iorIdentityFile, plusIdentitiesOnly yes - Public key in the right user's
authorized_keys, on one line -
700on~/.ssh,600onauthorized_keys, home not group-writable -
600on your private key -
sshd -T: AllowUsers, PermitRootLogin, AuthorizedKeysFile - Old RSA key? Generate ed25519
More server fixes, including our Linux server hardening checklist, are on the VeloxaHost blog.
Disclosure: we run VeloxaHost, a web hosting and VPS provider. Everything above works on any Linux server.

