Disable root in linux for SSH

I currently have about 4 servers and I have always used root to login into SSH. But now I realize that its a security risk so what can I do to not login via root?


Solution 1:

sudo vi /etc/ssh/sshd_config

Then uncomment or add the following:

PermitRootLogin no

Then restart sshd:

sudo /etc/init.d/sshd restart

Solution 2:

Look into /etc/ssh/sshd_config and set PermitRootLogin to no. Then restart sshd.

If you want to do administrative tasks through ssh, you can still use su (using roots password) or sudo (that has to be permitted in /etc/sudoers and you don't need the root password) to become root.

If you want your ssh deamon to be even more protected, you can login using public-key authentication. In that case, deactivate logins using passwords by setting PasswordAuthentication to no. Then you'll need keyfiles to login.

Solution 3:

Make a separate account and use sudo instead...