1. 程式人生 > >CentOS7下SSH登陸使用Google Authenticator兩步驗證

CentOS7下SSH登陸使用Google Authenticator兩步驗證

實驗環境:CentOS-7-x86_64-Minimal-1804

必須要關閉SELINUX

臨時關閉SELinux,重啟後失效:

setenforce 0

永久關閉,需要reboot重啟後生效:

vim /etc/selinux/config
SELINUX=disabled

github下載

編譯和安裝 ( Build & install )

安裝前準備:autoconf、automake、PAM庫等

sudo yum install autoconf automake libtool pam-devel
sudo ./bootstrap.sh
sudo ./configure
sudo
make sudo make install sudo cp .libs/pam_google_authenticator.so /lib64/security/

設定PAM元件

編輯pam.d下的sshd檔案,在第一行新增 儲存

sudo vim /etc/pam.d/sshd
auth required pam_google_authenticator.so

設定SSH配置檔案

編輯/etc/ssh/sshd_config找到下行
ChallengeResponseAuthentication no
改為
ChallengeResponseAuthentication yes

登陸

用xshell登陸的話,使用Keyboard Interactive驗證
先輸入驗證碼Verification code:
再輸入使用者密碼Password: