linux, website

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.

  1. Find sshd_config
    1. find . -name “sshd_config”
  2. Open the file up while logged in as root
    1. vi /etc/ssh/sshd_config
  3. Find the section containing the line “PermitRootLogin”
    1. /permitrootlogin
  4. Make the line look like this to disable root login through ssh
    1. PermitRootLogin no
  5. Save and close
    1. :wq
  6. Restart sshd service
    1. /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.

Leave a Reply

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

Time limit is exhausted. Please reload CAPTCHA.