Background: Two-factor authentication (abbreviated as: 2FA, hereinafter referred to as 2FA), where it is the second re-authentication of SSH. 2FA refers to a method of authenticating a user with both a password and a biometric symbol such as a credit card, SMS phone, token, or fingerprint. Through two different authentication procedures, can reduce the risk of password leakage, greatly improve the security of Linux system!
First, pre-configuration preparation
1, to prepare a running OpenSSH service Linux terminal.
2, an Android mobile phone.
Second, install Google authenticator on Linux
1. Install Google Identity authenticator on Ubuntu:
$ sudo apt-get install libpam-google-authenticator-y
2. Install Google identity authenticator on CentOS
#安装EPEL软件库 $ sudo yum install epel-release-y# installation google-authenticator$ sudo yum install-y google-authenticator
3. Running Google authenticator on a Linux host
$ google-authenticator
Google authenticator asks questions, always answer Y. The emergency backup verification code in the figure (shown in the figure: emergency scratch Codes) can resume access if you lose your bundled Android device. So, be sure to save the emergency backup verification code well!
Third, for the SSH server with Google Authenticator
1. Modify the PAM configuration file
$ sudo vim/etc/pam.d/sshd# Disallow non-root logins when/etc/nologin exists.account required pam_nologin.so# Add this line auth required pam_google_authenticator.so
2. Enable challengeresponseauthentication in SSH config file
$ sudo vim/etc/ssh/sshd_configchallengeresponseauthentication Yes
3. Restart the SSH service
$ sudo service ssh restart
Iv. running Google authenticator on your Android device
1. Search and install Google authenticator in the Android app market.
2. In the Configuration menu, enter the configuration information just
3, add the completion of the 6-digit dynamic code will be
To this, the two-factor authentication configuration is complete!
Configuration Reference Link: https://linux.cn/article-3725-1.html
Configure SSH dual authentication for Linux