SSH: `Permission denied (publickey)` when connecting to my server

asked 3 months ago124 viewsen

0

I generated a key with ssh-keygen and copied the .pub content into the server's authorized_keys, but I still get Permission denied (publickey).

AI diagnosis

AI-generated. Not an answer — the community below confirms or corrects it. Always verify before relying on it.

asked 3 months ago

1 Answer

6
✓
✓ Accepted answer

Go through the usual suspects:

1. Verbose output tells you which keys are being tried:

ssh -v user@server

2. Permissions on the server. SSH silently ignores keys when these are too open:

chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys
chown -R $USER:$USER ~/.ssh

(The home directory must not be group- or world-writable either.) 3. Right user: the key must be in /home/<that-user>/.ssh/authorized_keys for the user you're logging in as. 4. Right key on the client: if it's not a default name, specify it: ssh -i ~/.ssh/mykey user@server, or add a block to ~/.ssh/config:

Host prod
  HostName 203.0.113.10
  User deploy
  IdentityFile ~/.ssh/mykey

5. Pasting issues: the key must be one single line. 6. Server logs: sudo journalctl -u ssh (or /var/log/auth.log) shows the exact reason.

ssh-copy-id user@server avoids most of these mistakes.

Sign in to tell others whether this worked.

answered 3 months ago

Sign in and verify your email to post an answer.