Pcornel
Linux · SSH

Public Key Authentication

Cheat sheet · https://pcornel.dk/topic.php?topic=2802

Back to the Topic

Answer

Public key authentication logs in with a key pair: the private key stays on the client, the public key is placed in the server user's ~/.ssh/authorized_keys. The server checks a signature made with the private key.

Remember

Generate with ssh-keygen -t ed25519, copy with ssh-copy-id. Protect the private key with a passphrase and ssh-agent. Strict permissions are required on the server (~ not group-writable, ~/.ssh 700, authorized_keys 600).

First checks

  • ssh -v user@host — client-side connection and authentication steps
  • journalctl -u ssh -u sshd -e — server log
  • sshd -T — effective server settings
  • ss -ltnp | grep :22 — sshd listening

Verify in this order

client offers the public key → server finds it in authorized_keys → client signs a challenge → server verifies → login

Where it usually breaks

First mismatch in link/interface → address/namespace → route/neighbor → firewall/policy → socket/daemon → DNS/TLS/SSH/application peer path; preserve identity/native diagnostic/pre-state before mutation.

Read-only verification commands unless stated otherwise. Confirm syntax for your platform and release. Full reference: https://pcornel.dk/topic.php?topic=2802

Confirmation

Confirm action

Continue?