How to disable root SSH logins
One of the biggest security holes you could open on your Linux server is to allow directly logging in as root through ssh, because any cracker can attempt to brute force your root password and potentially get access to your system.
It’s much better to have separate account that you regularly use and simply sudo to root when necessary. Before we begin, you should make sure you have a regular user account and that you can “su” or “sudo” to root from it.
To fix this problem, we’ll need to edit the “sshd_config” file, which is the main configuration file for the sshd service. The location will sometimes be different, but it’s usually in /etc/ssh.
- Find sshd_config
- find . -name “sshd_config”
- Open the file up while logged in as root
- vi /etc/ssh/sshd_config
- Find the section containing the line “PermitRootLogin”
- Make the line look like this to disable root login through ssh
- PermitRootLogin no
- Save and close
- Restart sshd service
- /etc/init.d/ssh restart
Now nobody can brute force your root login, at least. This reduces the surface attack area dramatically as someone attacking your shell would have to guess many thousands of usernames then dictionary attack all of them.
This is just one of the steps to harden your shell, others include Fail2Ban and Public/Private keys, I will cover these in other blog posts.
Should you have any questions, comments or suggestions, please don’t hesitate to comment below. If you like what you have read, please share it on your favourite social media medium.