Knowledgebase

Find frequently asked questions and setup guides by searching or by browsing the categories.

What the Message Means

The word in brackets lists the login methods the server still allows. (publickey) means passwords are off and your keys did not work. Check the causes below in order; most cases end at the first or second.

1. Wrong User Name

A key is accepted per account. If you added it for deploy but connect as another user, the server rejects it. Cloud images often create a default user other than root; your provider's control panel shows which one. Name the user explicitly:

ssh user@your_server_ip

2. The Key Is Not Offered

Watch what the client does:

ssh -v user@your_server_ip

Look for lines that say which public keys are offered and whether the server accepted any. If your key is not in the list, name it:

ssh -i ~/.ssh/id_ed25519 -o IdentitiesOnly=yes user@your_server_ip

IdentitiesOnly=yes stops the agent from trying all its other keys first. Without it, a full agent can use up the server's attempt limit and the connection ends with "Too many authentication failures". Make it permanent in the SSH config file.

3. The Public Key Is Not on the Server

Log in through the provider's console and check:

cat /home/user/.ssh/authorized_keys

Compare the line with cat ~/.ssh/id_ed25519.pub on your computer. It must be one unbroken line. If the server reads keys from another place, sudo sshd -T | grep -i authorizedkeysfile shows the path. Add a missing key as described in ssh-copy-id.

4. Permissions or Ownership

sshd ignores authorized_keys if the home folder, ~/.ssh, or the file can be changed by other users, or if they belong to someone else. Fix all three:

sudo chmod go-w /home/user
sudo chmod 700 /home/user/.ssh
sudo chmod 600 /home/user/.ssh/authorized_keys
sudo chown -R user:user /home/user/.ssh

On AlmaLinux and Rocky Linux, a file copied into place can carry the wrong SELinux label. Restore it:

sudo restorecon -Rv /home/user/.ssh

See chown recursive for ownership in more depth.

5. Key Type Refused

Current OpenSSH servers reject DSA keys, and since OpenSSH 8.8 they no longer accept RSA signatures that use SHA-1 by default. An RSA key still works with a current client, but a DSA key, or a client too old to sign with SHA-2, can fail for that reason alone. Create a new Ed25519 key with ssh-keygen and install it.

6. A User Filter in the Configuration

The options AllowUsers, AllowGroups, DenyUsers, and DenyGroups limit who may log in at all. If one is set, your user must match it:

sudo sshd -T | grep -Ei 'allowusers|allowgroups|denyusers|denygroups'

Read the Server Log

The server usually states the exact reason. In the console, run

sudo journalctl -u ssh -n 50     # Ubuntu, Debian
sudo journalctl -u sshd -n 50    # AlmaLinux, Rocky Linux

On systems that also write text logs, the same lines are in /var/log/auth.log (Ubuntu, and Debian with rsyslog installed) or /var/log/secure (AlmaLinux, Rocky Linux). Since Debian 12, rsyslog is not installed by default, so on a new Debian server the journal is the only log. Follow them live while you retry with tail -f; look for messages about bad ownership or modes, or a user not allowed.

Was this answer helpful?
Loading...