Permission denied (publickey) for root login

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? Thanks.

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

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 id_rsa 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.

sudo nano /etc/ssh/sshd_config

Set PermitRootLogin to yes


sudo systemctl reload sshd


login as root