Founding prices until 15 December: 30% off Pro, locked for life. See pricing

$ … Permission denied (publickey)

SSH 'Permission denied (publickey)': how to find the cause

The server didn't accept any key the client offered.

Linux

What it means

The client offered keys and the server rejected all of them, or never got to check them. Either the client offers the wrong key, or the server ignores authorized_keys, most often because of loose permissions (StrictModes).

Causes and fixes

Most likely first. Run the check, and if it matches, apply the fix.

1. Loose permissions on the home directory, ~/.ssh or authorized_keys

Check:

ls -ld ~ ~/.ssh ~/.ssh/authorized_keys
journalctl -u ssh -n 20    # "Authentication refused: bad ownership or modes"

Fix: chmod 700 ~/.ssh; chmod 600 ~/.ssh/authorized_keys; the home directory not group- or world-writable; all owned by the user.

2. The client offers a different key, or none

Check:

ssh -v user@host 2>&1 | grep -E 'Offering|Trying|Authentications'

Fix: ssh -i ~/.ssh/the_key, or an IdentityFile entry in ~/.ssh/config.

3. The public key isn't in authorized_keys for that user (or has a line break in it)

Check:

ssh-keygen -lf ~/.ssh/id_ed25519.pub; ssh-keygen -lf ~user/.ssh/authorized_keys

Fix: Add the key as one line (ssh-copy-id).

4. sshd doesn't allow that user or key type (AllowUsers, PubkeyAuthentication no)

Check:

sshd -T | grep -E 'allowusers|pubkeyauthentication|authorizedkeysfile'

Fix: Change the effective setting; remember the first match wins in sshd_config.

Fix it yourself

A live machine in your browser with this problem already on it. The grader checks the result.

Open the lab

No account needed for your first tries.

Related errors

  • Permission denied

    The user the process runs as lacks the read, write or execute right on the file or a directory on its path.