If you’re accessing your server via SSH remotely and you want to add another layer of security to make sure it’s unauthorized user agents and threat actors can’t log in, then adding two-factor authentication is a great move. Two-factor authentication enables users to provide certain details such as random code, or OTP (Time Password ) to add another layer of security to standard usernames and passwords. We previously showed you how to set up two-factor authentication with Ubuntu using Google Authenticator. To read this post, click here. To get started with setting up two-factor authentication for SSH on Ubuntu using Google authenticator, follow the steps below:

Install Google Authenticator

Before you can configure the SSH server to enable two-factor or multi-factor access, you must first install Google Authentication. Since we’ve already shown you how to install Google Authenticator Ubuntu and set it up on your mobile device, please reference the post below so we don’t write it again. How to install Google Authenticator on Ubuntu Linux After setting up the steps above, continue below.

Configure Two-factor SSH

Now that you have installed Google Authenticator on Ubuntu and your mobile device, continue below to configure the SSH server to use it. To set up SSH run the commands below to open its default configuration file on Ubuntu. Next, make the highlighted changes in the file to make this work. Save and exit. Next, run the commands below to open the PAM SSH configuration file in Ubuntu. Then append the highlighted changes below and save. Save the file and exit. After making the changes above, restart the SSH service. Now go and test it out. You should be prompted for a one-time code every time you attempt to sign in. If you set up SSH public key authentication, then you’ll want to add this line in the main SSH configuration file at the/etc/ssh/sshd_config file. Then make sure this is included in the PAM SSH rule file at /etc/pam.d/sshd file. Exit both files and save your changes then restart SSH. That should do it! Conclusion: This post showed you how to configure SSH to accept two-factor authentication using Google Authenticator. If you find any error above, please use the form below to report. You may also like the post below: