google-authenticator ssh動態驗證登入
1 、安裝
yum -y install google-authenticator
注:如果沒有找到,要安裝epel-release源 ,yum -y install epel-release
或者YUM源安裝
yum -y install mercurial pam-devel bzip2
安裝Google Authenticator:
https://codeload.github.com/yangcvo/Google-Authenticator/zip/master //windows端下載直接傳到伺服器上
unzip Google-Authenticator-master.zip
cd Google-Authenticator-master/
tar -jxf libpam-google-authenticator-1.0-source.tar.bz2 cd libpam-google-authenticator-1.0 make make install
2、配置
SSH登入時呼叫google-authenticator模組,編輯: /etc/pam.d/sshd 第一行新增:
auth required pam_google_authenticator.so
修改SSH配置檔案: vim /etc/ssh/sshd_config 新增或修改以下內容: ChallengeResponseAuthentication yes
UsePAM yes
重啟SSH:
systemctl restart sshd
3、生成
完成後可通過google-authenticator命令對當前使用者建立隨機密碼,也會生成一個二維碼,之後選項都選擇yes即可;
建立後在家目錄下有個隱藏檔案為.google-authenticator的檔案,記住第一行私鑰
4、下載
然後就可以在手機上安裝google-authenticator客戶端,通過輸入私鑰即可實時顯示密碼,也可以使用二維碼掃碼實現
以後再遠端登入的時候就會彈出驗證碼,而要輸入客戶端上實時產生的動態驗證碼才能進行登入;