SSH is the secure shell which is used to access remote Linux systems. By default, when user access your server using SSH, they only type a username and password to log in. We often use it to connect with computers containing important data, it’s recommended to add another security layer.
Here comes the two factor authentication. With two-factor authentication, user have to provides another details with login username and password. This will provide extra layer of security. Follow these steps to configure and use two factor authentication.
To setup two-factor authentication, you need a non-root user with sudo permission. Server also need SSH key and firewall enabled. You also need phone or tablet with TOTP auth app installed like Google Authenticator or Authy.
After you logged into server, install Google authenticator package with below command.
sudo apt-get update
sudo apt-get install libpam-google-authenticator
Now to generate time-based one-time passwords on your device, run the below command.
google-authenticator
It will ask few questions. The first question will be:
Press y
and hit the Enter key. This will output the QR code. Scan this code in your TOTP application in phone or tablet.
Open the TOTP app and scan the QR code.
This will add account in Athentication application which will generate random OTP code every 30 seconds.
In the server, it will ask other few questions. Here is the recommended answers for questions.
The TOTP auth application will change token every 30 seconds. We will configure SSH to use TOTP auth application. To make SSH use Google Authenticator module, add the below lines in the /etc/pam.d/sshd
file.
Now restart the ssh deamon using below command.
sudo systemctl restart sshd.service
Open the /etc/ssh/sshd_config
file and change ChallengeResponseAuthentication
from no
to yes
.
That's it! You have configured two-factor authentication for SSH using TOTP auth. Now, every time when you try to log in to your server with SSH, you will be asked for an authentication key in addition to login username and password.
Hi, My name is Harsukh Makwana. i have been work with many programming language like php, python, javascript, node, react, anguler, etc.. since last 5 year. if you have any issue or want me hire then contact me on harsukh21@gmail.com
How to find character in string php
You can use the PHP strpos() f...How to compare two array values in PHP
Use the PHP array_diff() funct...Laravel 5.5 - Login With Only Mobile Number Using Laravel Custom Auth
Today, we are share with you how to modi...Create Function in Python with Example
Python Functions In this tutori...Check if Array is Empty or null in Javascript
When working in Javascript, many times y...