How to Disable SSH Password Authentication on Linux VPS
A lot of people use password authentication in order to connect to their servers with SSH command line. However, it is important to note that this authentication method might not be as safe as you might expect it to be; if an hacker succeeds in retrieving your SSH password, every bit of valuable information is at risk, this is why authenticating with SSH keys is the better option.
In this guide, we will show you how to disable password authentication for SSH on Linux VPS.
For this guide you will require the following things:
- A working Linux OS based server or VPS
- Root access to your server or VPS with SSH command line
Step 1 — Configuring SSH Key authentication on your server
Before starting this tutorial, make sure to note that if, you aren’t setting up another authentication method before disabling password authentication, you will have a hard time connecting to your server.
Step 2 — Editing SSH configuration file
Continue with this step only if you have completed the previous one and also successfully connected to your VPS. Otherwise; you may end up being locked out of your own server.
- Start by connecting to your VPS using the root SSH credentials.
- Next, open ‘/etc/ssh/sshd_config’ configuration file using a text editor such as ‘nano’ or ‘vim’ with an SSH command line: ‘nano /etc/ssh/sshd_config’
- Once the editor has been opened, you will have to look for a specific line: PasswordAuthentication yes. Nano has a search option which allows you to search for this line at ease by pressing CTRL + W and then typing the keyword ‘PasswordAuthentication’ and clicking ‘Enter’.
- This should then point you to the necessary section.
- You will now have to change ‘PasswordAuthentication yes’ to ‘PasswordAuthentication no’
- To save the changes, exit by pressing Ctrl + X, enter in the letter Y and press ‘Enter’.
- Finally, you will have to restart the SSHD service in order for the changes to be applied. Execute the command below.
service sshd restart
SSH password authentication should now be disabled. From this point on, no one is going to be able to access your VPS using the SSH password. Only privileged users who acquire the SSH keys that have been added to the server are going to be able to connect.
You should now know how to disable the SSH password authentication on your VPS. A strategy that can help your server to be a lot more secure as since no-one will be able to connect to your server with SSH using a password; only privileged users with SSH or other advanced authentication methods will be able to connect.