Permission denied (publickey) for root login

February 20, 2018 10k views
Applications DigitalOcean

It was working before but now somehow its not working.

ssh root@ gives below error message
Permission denied (publickey).

While for other user its working ( i.e ssh myUser@ )

I had tried many tutorials on digital oceans and from stackoverflow, but none working and I can't login with root.

Anybody has resolution?

3 Answers

Add your public key to /root/.ssh/authorized_keys.

This happens if you have multiple SSH keys loaded into your agent.

Lets say your key file is idrsa and respectivly

ssh -i ~/.ssh/id_rsa root@

If you don't want to type the -i aspect each time create a file in your .ssh folder named config and add an entry like below

Host whatever_name
    HostName or
    User root
    PreferredAuthentications publickey
    IdentityFile /path/to/.ssh/key_file
    UseKeychain yes
    AddKeysToAgent yes

update the entry to match your setup.

You get that error message when :
PasswordAuthentication no in /etc/sshd_config.

I changed it to "yes", ran 'service ssh restart' and all was well.
Changed it back to "no" and again ran 'service ssh restart'.
ssh to DO machine now works as intended.

NB:I don't allow password logins.

Have another answer? Share your knowledge.