Before you disable root logins you should add an administrative user that can ssh into the server and become root with su.
1. Add the user. In the following example we will use the user name admin. adduser will automatically create the user, initial group, and home directory. We will specify that we want to add admin to the “wheel” group.
[[email protected] ~]# id admin
uid=501(admin) gid=501(admin) groups=501(admin),10(wheel)
[[email protected] ~]# ls -lad /home/admin/
drwx—— 2 admin admin 4096 Nov 8 16:01 /home/admin/
2. Set the password for the admin user. When prompted type and then retype the password.
Changing password for user admin.
New UNIX password:
Retype new UNIX password:
passwd: all authentication tokens updated successfully.
[[email protected] ~]#
3. SSH to the server with the new admin user and ensure that the login works.
4. Verify that you can su (switch user) to root with the admin user.
5. Edit /etc/ssh/sshd_config with your favorite text editor.
6. Ensure that you are logged into the box with another shell before restarting sshd to avoid locking yourself out of the server.