新聞中心
這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷(xiāo)解決方案
SSH開(kāi)啟二次身份驗(yàn)證具體方法
目前來(lái)說(shuō),二次驗(yàn)證(這里就不做過(guò)多解釋了)是比較常用的安全手段,通過(guò)設(shè)置二次驗(yàn)證(谷歌或其他工具),就可以有效的避免賬戶(hù)密碼的泄露導(dǎo)致的安全問(wèn)題。因?yàn)椋看蔚顷懬岸夹枰@取一次性驗(yàn)證碼,如果沒(méi)有驗(yàn)證碼的話(huà)就無(wú)法成功登陸。

1安裝 PAM 模塊
# 時(shí)間與客戶(hù)端進(jìn)行校驗(yàn)
$ ntpdate pool.ntp.org
# Ubuntu
$ sudo apt install -y libpam-google-authenticator
# CentOS7
$ yum install -y epel-release
$ yum install -y google-authenticator
1.2.3.4.5.6.
2生成二次驗(yàn)證代碼
# 生成驗(yàn)證碼
# 哪個(gè)賬號(hào)需要?jiǎng)討B(tài)驗(yàn)證碼,請(qǐng)切換到該賬號(hào)下操作
# -t: 使用 TOTP 驗(yàn)證
# -f: 將配置保存到 ~/.google_authenticator 文件里面
# -d: 不允許重復(fù)使用以前使用的令牌
# -w 3: 使用令牌進(jìn)行身份驗(yàn)證以進(jìn)行時(shí)鐘偏移
# -e 10: 生成 10 個(gè)緊急備用代碼
# -r 3 -R 30: 限速 - 每 30 秒允許 3 次登錄
$ google-authenticator -t -f -d -w 3 -e 10 -r 3 -R 30
Warning: pasting the following URL into your browser exposes the OTP secret to Google:
https://www.google.com/chart?chs=200x200&chld=M|0&cht=qr&chl=otpauth://totp/vagrant@vagrant%3Fsecret%3DKZ7QPA11115XTQJQGBFWAIUJBY%26issuer%3Dvagrant
Your new secret key is: KZ7xxx7EI5123xxx123
Your verification code is 90xx71
Your emergency scratch codes are:
1571xx03
9968xx56
2319xx89
8321xx97
9730xx15
3424xx23
5667xx03
9408xx86
7502xx41
4677xx14
1.2.3.4.5.6.7.8.9.10.11.12.13.14.15.16.17.18.19.20.21.22.23.24.
3配置 SSH 服務(wù)啟用兩步驗(yàn)證
# 啟用兩步驗(yàn)證
$ sudo vim /etc/pam.d/sshd
# @include common-auth # 將禁用密碼身份驗(yàn)證
auth required pam_google_authenticator.so # 禁用密碼驗(yàn)證
# 修改SSH配置文件
$ sudo vim /etc/ssh/sshd_config
Port 1090
ChallengeResponseAuthentication yes
PubkeyAuthentication yes
PasswordAuthentication no
AuthenticationMethods publickey,keyboard-interactive
# 重啟SSH服務(wù)
$ sudo systemctl restart ssh.service
1.2.3.4.5.6.7.8.9.10.11.12.13.
4配置 sudo 二次驗(yàn)證
# 保存并退出
$ sudo vim /etc/pam.d/common-auth
auth required pam_google_authenticator.so
# 重啟SSH服務(wù)
$ sudo systemctl restart ssh.service
1.2.3.4.5.
5手機(jī)安裝 Google 身份驗(yàn)證器
1. 通過(guò)此工具掃描上一步生成的二維碼圖形,獲取動(dòng)態(tài)驗(yàn)證碼
2. 之后,就可以使用手機(jī)進(jìn)行二次認(rèn)證了,才能登陸服務(wù)器了
1.2.
6使用 Fail2ban 去屏蔽多次嘗試密碼的 IP
# 安裝軟件
$ sudo apt install -y fail2ban
# 配置文件
$ vim /etc/fail2ban/jail.local
[DEFAULT]
ignoreip = 127.0.0.1/8
bantime = 86400
findtime = 600
maxretry = 5
banaction = firewallcmd-ipset
action = %(action_mwl)s
[sshd]
enabled = true
filter = sshd
port = 1090
action = %(action_mwl)s
logpath = /var/log/secure
1.2.3.4.5.6.7.8.9.10.11.12.13.14.15.16.17.
# 重啟服務(wù)
$ systemctl restart fail2ban
1.2.
7從二次驗(yàn)證鎖定中恢復(fù)
# 禁用特定用戶(hù)的二步驗(yàn)證(無(wú)法訪問(wèn)身份驗(yàn)證器應(yīng)用程序)
$ sudo vim /etc/ssh/sshd_config
AuthenticationMethods publickey,keyboard-interactive
AuthenticationMethods publickey
# 重啟SSH服務(wù)
$ sudo systemctl restart ssh.service
分享名稱(chēng):SSH開(kāi)啟二次身份驗(yàn)證具體方法
網(wǎng)站路徑:http://m.fisionsoft.com.cn/article/cossspj.html


咨詢(xún)
建站咨詢(xún)
