ssh root@host – Permission denied, please try again.

This error usually occurs if PermitRootLogin is set to without-password meaning ssh keys should be used instead.
Currently i only have access to my server via the web console provided by my hosting provider.
To setup ssh you need to add your public key to

Simple enough, but when the console doesn’t allow copy and paste it would be a rather tedious experience.

So by permitting root login with a password (temporarily) you can then access the server from your machine, add the ssh key (without having to type it manually) and then set PermitRootLogin back to without-password.

Once you’ve logged-in the fix is simple, edit the /etc/ssh/sshd_config file,
nano /etc/ssh/sshd_config

replace the line starting with PermitRootLogin(if it exists) with PermitRootLogin yes

and then for the changes to take affect you will need to restart the ssh service

sudo service ssh restart

After a few seconds go back to your own terminal and attempt to login again
ssh root@[]

You should be prompted for your password as usual but this time you shouldn’t receive an error.

So that fixed the problem but now anyone can login from anywhere (if the correct password is entered)

You should really use an ssh key, if your not sure if you have one heres some very useful articles from Github

If you are still logged in to the remote host type `exit` the enter the following command

cat ~/.ssh/ | ssh root@[] "cat >> ~/.ssh/authorized_keys"

remember to replace with the remote host, You should be prompted for your password one last time.

If nothing seems to happen thats great.

Now attempt to login again
ssh root@[]

This time you shouldn’t be prompted for a password, now you have access from another machine you can change PermitRootLogin back to without-password.

Still in your own terminal edit the /etc/ssh/sshd_config file again,
nano /etc/ssh/sshd_config

an now replace PermitRootLogin yes with PermitRootLogin without-password


sudo service ssh restart

then try logging in again ssh root@[]

You can check this has worked by trying to login via a machine without SSH setup.

Leave a Reply

Your email address will not be published. Required fields are marked *