系統(tǒng):CentOS 7.5 X64
#安裝開發(fā)者工具
yum groupinstall “Development Tools” -y
#安裝pam 開發(fā)包
yum install pam-devel -y
#安裝chrony軟件,chrony 是網(wǎng)絡(luò)時(shí)間協(xié)議的(NTP)的另一種實(shí)現(xiàn),因?yàn)閯?dòng)態(tài)口令再驗(yàn)證時(shí)用到了時(shí)間,所以要保持時(shí)間上的一致性
yum install chrony -y
vi /etc/chrony.conf
…
server 2.cn.pool.ntp.org iburst
systemctl restart chronyd
chronyc sources
#如果時(shí)區(qū)不對(duì)的話,可以拷貝你當(dāng)前地區(qū)所在地的時(shí)區(qū)到系統(tǒng)運(yùn)行的時(shí)區(qū)
#cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
###安裝google-authenticator
cd /opt
git clone https://github.com/google/google-authenticator-libpam.git
cd google-authenticator-libpam/
./bootstrap.sh
./configure
make && make install
ln -s /usr/local/lib/security/pam_google_authenticator.so /usr/lib64/security/pam_google_authenticator.so
#配置系統(tǒng)PAM模塊,修改sshd支持谷歌的認(rèn)證,在sshd文件的第一行
vi /etc/pam.d/sshd
auth required pam_google_authenticator.so
vi /etc/ssh/sshd_config
…
ChallengeResponseAuthentication yes
#安裝二維碼生成工具,這步也可以省略,如果不裝的話,因?yàn)橄乱徊缴傻亩S碼就會(huì)成一個(gè)鏈接,
#到時(shí)將鏈接復(fù)制到你的瀏覽器中,也是可以出現(xiàn)二維碼的,到時(shí)利用智能手機(jī)打開google author 進(jìn)行掃描。
cd /opt
yum -y install libpng libpng-devel
wget -c https://fukuchi.org/works/qrencode/qrencode-4.0.2.tar.bz2
tar jxvf qrencode-4.0.2.tar.bz2
cd qrencode-4.0.2
./configure
make && make install
#運(yùn)行g(shù)oogle-authenticator命令,它將會(huì)在當(dāng)前登陸用戶的家目錄中生成一個(gè)新的密鑰
cd ~
google-authenticator
#Your emergency scratch codes are:
# 98627355
# 45083255
# 48589468
# 91373042
# 22191496
#上述共需回答5個(gè)y
#第1個(gè):?jiǎn)柲闶欠裣胱鲆粋€(gè)基于時(shí)間的令×××y
#第2個(gè):是否更新你的google認(rèn)證文件,由于第一次設(shè)置,所以一定選y
#第3個(gè):是否禁止口令多用,這里選擇y,禁止它,以防止中間人欺騙。y
#第4個(gè):默認(rèn)情況,1個(gè)口令的有效期是30s,這里是為了防止主機(jī)時(shí)間和口令客戶端時(shí)間不一致,設(shè)置的誤差,可以選擇y,也可選n,看要求嚴(yán)謹(jǐn)程度y
#第5個(gè):是否打開嘗試次數(shù)限制,默認(rèn)情況,30s內(nèi)不得超過3次登陸測(cè)試,防止別人暴力破解。y
#并且上面這些設(shè)置將被存儲(chǔ)在用戶的/.google_authenticator文件中,emergency scratch codes 中的5個(gè)代碼是緊急代碼,務(wù)必牢記,
#這是在你的動(dòng)態(tài)口令無法使用的情況下使用的,記住,用一個(gè)失效一個(gè)。后期可以登陸上去后,重新生成!
#此時(shí)打開手機(jī)上的Google Authenticator應(yīng)用掃描二維碼
#最后重啟sshd服務(wù)
systemctl restart sshd
###— secureCRT設(shè)置keyboard interactive需要放在第一位 —###
### 解決內(nèi)網(wǎng)主機(jī)跳過二次認(rèn)證
#編輯pam.d下的sshd 文件,在第一行增加內(nèi)容,主要是指定允許的主機(jī)信息文件
more -2 /etc/pam.d/sshd
auth [success=1 default=ignore] pam_access.so accessfile=/etc/security/access-localhost.conf
auth required pam_google_authenticator.so no_increment_hotp
#然后在/etc/security/目錄下創(chuàng)建access-localhost.conf文件
cat /etc/security/access-localhost.conf
# skipped local network for google auth…
+ : ALL : 192.168.11.0/24
+ : ALL : LOCAL
– : ALL : ALL
#最后重啟sshd服務(wù)
systemctl restart sshd