Fix Linux Preventing Remote SSH Root Login Issue

This is a simple post that handles the issue of Please login as the user “rocky” rather than the user “root”.

I have this problem on my Rocky Linux 9, it prevents me to login as root as I’ve already uploaded the public key to the server. So at the end of the ssh session it outputs: Please login as the user “rocky” rather than the user “root”.

One good thing is that I know what user I need to specify for ssh login, I replaced root with rocky user, no other changes are made, I was allowed to login to the server.

The first thing I did was to check /etc/ssh/sshd_config and see if root login is permitted, so you need to uncomment PermitRootLogin prohibit-password, once this is done, you need to reload systemd by systemctl restart sshd.

However, when I tried to login with root again, I still could not be able to do, I received the same problem.

I then decided to check the authorized_keys in root’s home folder, it turns out I found something interesting.

So authorized_keys contains public keys that allow devices to login remotely. I found that the public key I uploaded was modified by adding the following text before the public key.

no-port-forwarding,no-agent-forwarding,no-X11-forwarding,command="echo 'Please login as the user \"rocky\" rather than the user \"root\".';echo;sleep 10;exit 142" ssh-rsaxxxx
ShellScript

It turns out I only need to delete the text before ssh- string, which is the public key. Then it is easy to login as root and perform tasks on host machine.


Posted

in

by

Tags:

Comments

Leave a Reply

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