Fix SSH "Permission denied (publickey,password)"

This error means you reached the server and SSH works, but it rejected your identity: wrong password or username, a key it does not accept, or password login turned off.

Last updated:

Check the username first

Many ready images do not accept root directly and use a name such as ubuntu or admin. Type the password by hand, because pasting can add a trailing space. The terminal shows nothing while you type.

terminal
$ ssh ubuntu@SERVER_IP
$ ssh -v root@SERVER_IP

Is password login turned off?

If the error names only publickey, the server does not accept passwords. Check the effective setting from the console. To allow passwords, set PasswordAuthentication to yes in /etc/ssh/sshd_config and restart the service.

console
$ sudo sshd -T | grep -Ei "passwordauthentication|permitrootlogin"
$ sudo systemctl restart ssh

Logging in with an SSH key

Name your key explicitly and make sure the public key is in that user's authorized_keys file. SSH refuses keys when file permissions are too open. These are the correct permissions.

terminal
$ ssh -i ~/.ssh/id_ed25519 root@SERVER_IP
console
$ chmod 700 ~/.ssh
$ chmod 600 ~/.ssh/authorized_keys

The server log tells you the real reason

The reason for the refusal is in the log, such as bad permissions or a user that is not allowed. Run this from the console while you try to log in from your computer.

console
$ sudo journalctl -u ssh -f
Was this page helpful?