VPS

How to Disable SSH Password Authentication on Linux VPS

Introduction

The majority of people use password authentication to connect to their servers via SSH command line and do not even consider that this authentication method may not be as safe as they expected. Consider this: if any hacker manages to collect your SSH password, all of your valuable information is at risk. That is why authenticating with SSH keys is a better option.

In this tutorial you will learn how to disable password authentication for SSH on Linux VPS.

What you’ll need

Before you begin this guide you’ll need the following:

  • A working Linux OS based server / VPS
  • Root access to your server / VPS via SSH command line

Step 1 — Configuring SSH Key authentication on your server

Before we start the guide, you should note that if you do not set up another authentication method beforehand and disable password authentication right away, you will have a hard time connecting to your server.

It is very IMPORTANT to configure another way of authentication before you proceed with this guide. We recommend SSH Key authentication. This is a full tutorial on how to configure SSH Key authentication on your server: How To Set Up SSH Keys

IMPORTANT! Continue with this tutorial only after you configure your SSH Keys because you may be locked out of your own server!

Step 2 — Editing SSH configuration file

Proceed with this only if you have completed Step 1 and successfully connected to your VPS using [SSH keys](https://www.hostinger.com/tutorials/ssh/how-to-set-up-ssh-keys because you may be locked out of your own server.

  1. Connect to your server/VPS with root SSH credentials.
  2. Open /etc/ssh/sshd_config configuration file with a text editor like nano or vim via SSH command line. nano /etc/ssh/sshd_config
  3. When editor opens you should see a similar view:
    sshd config
  4. Now you need to find a line: PasswordAuthentication yes. Nano has a search feature so you can simply search for this line by pressing CTRL + W on your keyboard, writing a search keyword PasswordAuthentication and clicking Enter.
    nano search password authentication
  5. Your pointer should point to the necessary area.
    find password authentication area
  6. And here you need to change PasswordAuthentication yes to PasswordAuthentication no:
    change password authentication method
  7. To save changes and exit press Ctrl + X, type in Y and press Enter button.
  8. Additionally, you need to restart the SSHD service to apply the changes. Run the following command: service sshd restart

And that is it! SSH password authentication has been disabled. From this point no one will be able to connect to your server / VPS using SSH password. Only privileged users who have their SSH keys added to your server will be able to connect.

Conclusion

You have learned how to disable SSH password authentication on your server / VPS. This makes your server a lot safer because no one will be able to connect to your server via SSH using a password. Only privileged users using SSH keys or other advanced authentication methods will be able to connect.

About the author

Linas L.

Linas started as customer success agent and now is a full-stack web developer at Hostinger. He is passionate about making a positive impact on people by utilizing user driven development techniques. As much as he enjoys coding and changing the world, he secretly dreams of becoming a rock star.

Add Comment

Click here to post a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Black Friday Sale 90% OFF
0
DAYS
0
HOURS
0
MINUTES
0
SECONDS
×
[href]
[href]
More in VPS
How to Change Permissions and Owners via Command Line

Close