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

poze 3 months ago122 gadeen

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).

Dyagnostik IA

Se IA ki fè l. Se pa yon repons — kominote a anba a konfime oswa korije l. Toujou verifye anvan ou fye l.

poze 3 months ago

1 Repons

6
✓
✓ Repons yo aksepte

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.

Konekte pou di lòt moun si li te mache.

answered 3 months ago

Sign in and verify your email to post an answer.