現場(環境):CentOS 7 套件: google-authentication
大家登入gmail的時候,可能都有注意到,
可以透過gmail發送簡訊到手機,進行兩階段的認證動作。
這個概念現在可以套用到系統登入的層面,
原本只用密碼登入這件事,可能沒有這麼的合乎安全性的問題。
現在我們透過google-authentication來測試看看這個驗證方式。
Step0.添加CentOS 7的epel
# yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm -y
Step1.先安裝相依性套件
# yum install gcc make pam-devel libpng-devel libtool wget git –y
# yum groupinstall "Development Tools"-y
# yum install pam-devel -y
Google用這個套件產生二維條碼登入
# yum install qrencode -y
Step2. 下載並安裝google驗證器 (建議直接安裝這個就好)
# yum install google-authenticator -y
或者自行編譯
=!=================================
#git clone https://github.com/google/google-authenticator-libpam.git
#cd google-authenticator-libpam/
#./bootstrap.sh
#./configure --prefix=/usr/local/google-authenticator
#make && make install
複製到/usr/lib64/security
cp /usr/local/google-authenticator/lib/security/pam_google_authenticator.so /lib64/security/
=!===================================
Step3. 設定ssh連線資訊
#vim /etc/ssh/sshd_config
=!===========
#將下方這行修改為yes
ChallengeResponseAuthentication yes
=!===========
#vim /etc/ssh/sshd_config
=!===========
#加入驗證模式
UsePAM yes
=!===========
重啟sshd服務
#systemctl restart sshd
Step4. 設定pam
開始設定/etc/pam.d/sshd
#vim /etc/pam.d/sshd
=!==================================
#添加下面的設定 (二擇一)
auth substack password-auth
auth required pam_google_authenticator.so
OR
( 這個LAB選擇這個使用 )
auth substack password-auth
auth required pam_google_authenticator.so nullok
=!==================================
這邊的順序將確定先輸入密碼還是動態碼
nullok的作用是讓未設定google-auth的Account
能夠單次認證登入,可自行考量實際環境變更此參數
Step5. 啟動google-authentication **需要網路**
# google-authentication
操作部分基本上都先輸入[ y ]
之後就會顯示QR code要用來驗證,或者輸入下方Verification code來驗證。
Emergency scratch code是沒有手機時的緊急登入代碼。
之後這邊的檔案會存在家目錄下的.google_authenticator之中。
!!使用者手機安裝Google Authenticator APP
這邊需要使用者用手機掃描QR code加入認證。
之後一路按[ y ]就好。
Step6. 利用手機綁定 (google authenticator APP要先去安裝喔)
這邊可以決定要用QR code或者輸入帳號&序號來綁定。
建議直接用掃QR code的方式去帶入,不然容易有錯誤的狀況發生。
人工設定也可以,但有輸入錯誤的可能性。
設定之後可以看到序號方面的資訊
之後登入就要輸入那個序號來驗證
正常登入後就完成設定了,大致上操作就這樣
補充:
1.啟用時,也可以帶參數自動建立完成驗證碼
# google-authenticator -t -d -f -r 3 -R 30 -W
2.這邊是在sshd當中添加,當然也可以考慮在su當中添加。
這個時候只要將設定加到/etc/pam.d/su就可以了。
<本篇完>
參考網址:
https://www.itread01.com/content/1525430439.html
https://www.itread01.com/content/1508331485.html
https://www.howtoing.com/how-to-set-up-multi-factor-authentication-for-ssh-on-centos-7
https://shenyu.me/2016/09/05/centos-google-authenticator.html