Disabling SSH Password Authentication and Root Login for Ubuntu

You just strengthened the security of your Server by adding a new user and generating SSH keys. Now it’s time to make some changes to the default SSH configuration. First, you’ll disablepassword authentication to require all users connecting via SSH to use key authentication. Next, you’ll disable root login to prevent the root user from logging in via SSH. These steps are optional, but are strongly recommended.
Here’s how to disable SSH password authentication and root login:
Open the SSH configuration file for editing by entering the following command:

sudo nano /etc/ssh/sshd_config

Change the PasswordAuthentication setting to no as shown below. Verify that the line is uncommented by removing the # in front of the line, if there is one.:

PasswordAuthentication no

Change the PermitRootLogin setting to no as shown below:

PermitRootLogin no

Save the changes to the SSH configuration file by pressing Control-X, and then Y.

Restart the SSH service to load the new configuration. Enter the following command:

sudo service ssh restart

After the SSH service restarts, the SSH configuration changes will be applied.

  • 61 Users Found This Useful
Was this answer helpful?

Related Articles

How to add a new user on Ubuntu

The problem with logging in as root is that you can execute any command - even a command that...

How to Install a Firewall on Ubuntu

So you want to setup a firewall to limit and block unwanted inbound traffic to your Server....

Installing and Configuring Fail2Ban for Ubuntu

Fail2Ban is an application that prevents dictionary attacks on your server. When Fail2Ban detects...

Initial Steps to securing your Ubuntu server

Securing your Ubuntu server is a big step in the right direction and most importantly it will...