Linux服務(wù)器通過ssh遠(yuǎn)程連接的時(shí)候,如果使用的是用戶名+密碼的驗(yàn)證方式,萬一密碼泄露或者密碼過于簡單被暴li破解,服務(wù)器的安全就得不到保障。由此,可以結(jié)合谷歌動(dòng)態(tài)驗(yàn)證口令來為服務(wù)器再加一道安全防護(hù)門。此時(shí),就算是用戶密碼被泄露,但沒有動(dòng)態(tài)驗(yàn)證口令也是無法登錄服務(wù)器的。
網(wǎng)站建設(shè)哪家好,找創(chuàng)新互聯(lián)建站!專注于網(wǎng)頁設(shè)計(jì)、網(wǎng)站建設(shè)、微信開發(fā)、小程序開發(fā)、集團(tuán)企業(yè)網(wǎng)站建設(shè)等服務(wù)項(xiàng)目。為回饋新老客戶創(chuàng)新互聯(lián)還提供了棗陽免費(fèi)建站歡迎大家使用!
OS:CentOS7
軟件包:google-authenticator.x86_64
安卓手機(jī)一部(某米)
谷歌動(dòng)態(tài)口令的下載及使用自行百度
1.一鍵安裝腳本
#安裝epel
yum install -y epel-release.noarch &> /dev/null
yum makecache &> /dev/null
#安裝google authenticator
yum install -y google-authenticator.x86_64 &> /dev/null
echo -e "\033[31mDo you want me to update your "/root/.google_authenticator" file? (y/n) y"
echo -e "\033[31m你希望我更新你的“/root/.google_authenticator”文件嗎(y/n)?\033[0m"
echo -e "\033[31mDo you want to disallow multiple uses of the same authentication"
echo -e "\033[31mtoken? This restricts you to one login about every 30s, but it increases"
echo -e "\033[31myour chances to notice or even prevent man-in-the-middle attacks (y/n) y"
echo -e "\033[31m你希望禁止多次使用同一個(gè)驗(yàn)證令牌嗎?這限制你每次登錄的時(shí)間大約是30秒, 但是這加大了發(fā)現(xiàn)甚至防止中間人攻ji的可能性(y/n)?\033[0m"
echo -e "\033[31mBy default, a new token is generated every 30 seconds by the mobile app."
echo -e "\033[31mIn order to compensate for possible time-skew between the client and the server,"
echo -e "\033[31mwe allow an extra token before and after the current time. This allows for a"
echo -e "\033[31mtime skew of up to 30 seconds between authentication server and client. If you"
echo -e "\033[31mexperience problems with poor time synchronization, you can increase the window"
echo -e "\033[31mfrom its default size of 3 permitted codes (one previous code, the current"
echo -e "\033[31mcode, the next code) to 17 permitted codes (the 8 previous codes, the current"
echo -e "\033[31mcode, and the 8 next codes). This will permit for a time skew of up to 4 minutes"
echo -e "\033[31mbetween client and server."
echo -e "\033[31mDo you want to do so? (y/n) y"
echo -e "\033[31m默認(rèn)情況下,令牌保持30秒有效;為了補(bǔ)償客戶機(jī)與服務(wù)器之間可能存在的時(shí)滯,\033[0m"
echo -e "\033[31m我們允許在當(dāng)前時(shí)間前后有一個(gè)額外令牌。如果你在時(shí)間同步方面遇到了問題, 可以增加窗口從默認(rèn)的3個(gè)可通過驗(yàn)證碼增加到17個(gè)可通過驗(yàn)證碼,\033[0m"
echo -e "\033[31m這將允許客戶機(jī)與服務(wù)器之間的時(shí)差增加到4分鐘。你希望這么做嗎(y/n)?\033[0m"
echo -e "\033[31mIf the computer that you are logging into isn't hardened against brute-force"
echo -e "\033[31mlogin attempts, you can enable rate-limiting for the authentication module."
echo -e "\033[31mBy default, this limits attackers to no more than 3 login attempts every 30s."
echo -e "\033[31mDo you want to enable rate-limiting? (y/n) y"
echo -e "\033[31m如果你登錄的那臺(tái)計(jì)算機(jī)沒有經(jīng)過固化,以防范運(yùn)用蠻力的登錄企圖,可以對驗(yàn)證模塊\033[0m"
echo -e "\033[31m啟用嘗試次數(shù)限制。默認(rèn)情況下,這限制攻ji者每30秒試圖登錄的次數(shù)只有3次。 你希望啟用嘗試次數(shù)限制嗎(y/n)?\033[0m"
echo -e "\033[32m 在App Store 搜索Google Authenticator 進(jìn)行App安裝 \033[0m"
expect << EOF
spawn google-authenticator
expect {
"y/n" {send "y\n";exp_continue}
"y/n" {send "y\n"}
"y/n" {send "y\n"}
"y/n" {send "y\n"}
}
EOF
#/etc/pam.d/sshd文件,修改或添加下行保存
#auth required pam_google_authenticator.so
sed -i '1a\auth required pam_google_authenticator.so' /etc/pam.d/sshd
#編輯/etc/ssh/sshd_config找到下行
#ChallengeResponseAuthentication no
#更改為
#ChallengeResponseAuthentication yes
sed -i 's/ChallengeResponseAuthentication no/ChallengeResponseAuthentication yes/' /etc/ssh/sshd_config
#重啟SSH服務(wù)
systemctl restart sshd
2.運(yùn)行腳本后直接掃屏幕生成的二維碼或者復(fù)制二維碼上方的URL到瀏覽器打開后掃碼,然后使用掃碼生成的動(dòng)態(tài)口令進(jìn)行登錄
2.1打開遠(yuǎn)程連接工具xshell,如圖
2.2輸入動(dòng)態(tài)口令
2.3輸入服務(wù)器密碼
2.4查看/var/log/secure日志可以發(fā)現(xiàn)ssh遠(yuǎn)程登錄通過了pam_google_authenticator動(dòng)態(tài)模塊的驗(yàn)證并且成功登錄服務(wù)器
1.使用某米手機(jī)掃二維碼的時(shí)候出現(xiàn)如下提示
于是安裝了Google play應(yīng)用,但是打開后閃退,搜索相關(guān)資料后貌似是沒有谷歌服務(wù)框架的原因,于是又下載了谷歌服務(wù)框架應(yīng)用,仍然沒有成功,可能科學(xué)上網(wǎng)可以解決此問題。
由于時(shí)間問題沒再折騰,后面換了某為手機(jī)就行了。
2.如果手機(jī)掃碼不成功,可以chrome 網(wǎng)上應(yīng)用店搜索“身份驗(yàn)證器”插件,然后添加到Chrome瀏覽器進(jìn)行掃碼
3.如果手機(jī)丟失或者其它情況導(dǎo)致無法獲取到動(dòng)態(tài)口令,可以使用緊急刮刮碼來登錄服務(wù)器,默認(rèn)配置文件是/root/.google_authenticator,不過這里面的刮刮碼用一個(gè)少一個(gè),建議保存到安全的地方。
網(wǎng)頁標(biāo)題:如何實(shí)現(xiàn)SSH通過掃二維碼登錄Linux服務(wù)器
文章來源:http://www.chinadenli.net/article38/ggihsp.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供軟件開發(fā)、網(wǎng)站收錄、手機(jī)網(wǎng)站建設(shè)、品牌網(wǎng)站建設(shè)、電子商務(wù)、網(wǎng)站排名
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)