Linux服務(wù)器通過ssh遠程連接的時候,如果使用的是用戶名+密碼的驗證方式,萬一密碼泄露或者密碼過于簡單被暴li破解,服務(wù)器的安全就得不到保障。由此,可以結(jié)合谷歌動態(tài)驗證口令來為服務(wù)器再加一道安全防護門。此時,就算是用戶密碼被泄露,但沒有動態(tài)驗證口令也是無法登錄服務(wù)器的。

OS:CentOS7
軟件包:google-authenticator.x86_64
安卓手機一部(某米)
谷歌動態(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你希望禁止多次使用同一個驗證令牌嗎?這限制你每次登錄的時間大約是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默認情況下,令牌保持30秒有效;為了補償客戶機與服務(wù)器之間可能存在的時滯,\033[0m"
echo -e "\033[31m我們允許在當(dāng)前時間前后有一個額外令牌。如果你在時間同步方面遇到了問題, 可以增加窗口從默認的3個可通過驗證碼增加到17個可通過驗證碼,\033[0m"
echo -e "\033[31m這將允許客戶機與服務(wù)器之間的時差增加到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如果你登錄的那臺計算機沒有經(jīng)過固化,以防范運用蠻力的登錄企圖,可以對驗證模塊\033[0m"
echo -e "\033[31m啟用嘗試次數(shù)限制。默認情況下,這限制攻ji者每30秒試圖登錄的次數(shù)只有3次。 你希望啟用嘗試次數(shù)限制嗎(y/n)?\033[0m"
echo -e "\033[32m 在App Store 搜索Google Authenticator 進行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 sshd2.運行腳本后直接掃屏幕生成的二維碼或者復(fù)制二維碼上方的URL到瀏覽器打開后掃碼,然后使用掃碼生成的動態(tài)口令進行登錄
2.1打開遠程連接工具xshell,如圖
2.2輸入動態(tài)口令
2.3輸入服務(wù)器密碼
2.4查看/var/log/secure日志可以發(fā)現(xiàn)ssh遠程登錄通過了pam_google_authenticator動態(tài)模塊的驗證并且成功登錄服務(wù)器
1.使用某米手機掃二維碼的時候出現(xiàn)如下提示
于是安裝了Google play應(yīng)用,但是打開后閃退,搜索相關(guān)資料后貌似是沒有谷歌服務(wù)框架的原因,于是又下載了谷歌服務(wù)框架應(yīng)用,仍然沒有成功,可能科學(xué)上網(wǎng)可以解決此問題。
由于時間問題沒再折騰,后面換了某為手機就行了。
2.如果手機掃碼不成功,可以chrome 網(wǎng)上應(yīng)用店搜索“身份驗證器”插件,然后添加到Chrome瀏覽器進行掃碼



3.如果手機丟失或者其它情況導(dǎo)致無法獲取到動態(tài)口令,可以使用緊急刮刮碼來登錄服務(wù)器,默認配置文件是/root/.google_authenticator,不過這里面的刮刮碼用一個少一個,建議保存到安全的地方。
另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)cdcxhl.cn,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國服務(wù)器、虛擬主機、免備案服務(wù)器”等云主機租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務(wù)可用性高、性價比高”等特點與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場景需求。
文章名稱:如何實現(xiàn)SSH通過掃二維碼登錄Linux服務(wù)器-創(chuàng)新互聯(lián)
網(wǎng)站路徑:http://www.chinadenli.net/article30/pojso.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供外貿(mào)建站、全網(wǎng)營銷推廣、電子商務(wù)、響應(yīng)式網(wǎng)站、服務(wù)器托管、微信小程序
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)