自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

手把手教你給 SSH 啟用二次身份驗證

系統(tǒng) Linux
目前來說,二次驗證(這里就不做過多解釋了)是比較常用的安全手段,通過設(shè)置二次驗證(谷歌或其他工具),就可以有效的避免賬戶密碼的泄露導(dǎo)致的安全問題。

[[440376]]

 目前來說,二次驗證(這里就不做過多解釋了)是比較常用的安全手段,通過設(shè)置二次驗證(谷歌或其他工具),就可以有效的避免賬戶密碼的泄露導(dǎo)致的安全問題。因為,每次登陸前都需要獲取一次性驗證碼,如果沒有驗證碼的話就無法成功登陸。

1安裝 PAM 模塊

# 時間與客戶端進行校驗 

  1. $ ntpdate pool.ntp.org  
  2. # Ubuntu  
  3. $ sudo apt install -y libpam-google-authenticator  
  4. # CentOS7  
  5. $ yum install -y epel-release  
  6. $ yum install -y google-authenticator 

2生成二次驗證代碼 

  1. # 生成驗證碼  
  2. # 哪個賬號需要動態(tài)驗證碼,請切換到該賬號下操作  
  3. # -t: 使用 TOTP 驗證  
  4. # -f: 將配置保存到 ~/.google_authenticator 文件里面  
  5. # -d: 不允許重復(fù)使用以前使用的令牌  
  6. # -w 3: 使用令牌進行身份驗證以進行時鐘偏移  
  7. # -e 10: 生成 10 個緊急備用代碼  
  8. # -r 3 -R 30: 限速 - 每 30 秒允許 3 次登錄  
  9. $ google-authenticator -t -f -d -w 3 -e 10 -r 3 -R 30  
  10. Warning: pasting the following URL into your browser exposes the OTP secret to Google: 
  11.   https://www.google.com/chart?chs=200x200&chld=M|0&cht=qr&chl=otpauth://totp/vagrant@vagrant%3Fsecret%3DKZ7QPA11115XTQJQGBFWAIUJBY%26issuer%3Dvagrant  
  12. Your new secret key is: KZ7xxx7EI5123xxx123  
  13. Your verification code is 90xx71  
  14. Your emergency scratch codes are:  
  15.   1571xx03  
  16.   9968xx56  
  17.   2319xx89  
  18.   8321xx97  
  19.   9730xx15  
  20.   3424xx23  
  21.   5667xx03  
  22.   9408xx86  
  23.   7502xx41  
  24.   4677xx14 

3配置 SSH 服務(wù)啟用兩步驗證 

  1. # 啟用兩步驗證  
  2. $ sudo vim /etc/pam.d/sshd  
  3. # @include common-auth  # 將禁用密碼身份驗證  
  4. auth required pam_google_authenticator.so  # 禁用密碼驗證  
  5. # 修改SSH配置文件  
  6. $ sudo vim /etc/ssh/sshd_config  
  7. Port 1090  
  8. ChallengeResponseAuthentication yes  
  9. PubkeyAuthentication yes  
  10. PasswordAuthentication no  
  11. AuthenticationMethods publickey,keyboard-interactive  
  12. # 重啟SSH服務(wù)  
  13. $ sudo systemctl restart ssh.service 

4配置 sudo 二次驗證 

  1. # 保存并退出  
  2. $ sudo vim /etc/pam.d/common-auth  
  3. auth required pam_google_authenticator.so  
  4. # 重啟SSH服務(wù)  
  5. $ sudo systemctl restart ssh.service  

5手機安裝 Google 身份驗證器 

  1. 1. 通過此工具掃描上一步生成的二維碼圖形,獲取動態(tài)驗證碼  
  2. 2. 之后,就可以使用手機進行二次認證了,才能登陸服務(wù)器了  

6使用 Fail2ban 去屏蔽多次嘗試密碼的 IP 

  1. # 安裝軟件  
  2. $ sudo apt install -y fail2ban  
  3. # 配置文件  
  4. $ vim /etc/fail2ban/jail.local  
  5. [DEFAULT]  
  6. ignoreip = 127.0.0.1/8  
  7. bantime  = 86400  
  8. findtime = 600  
  9. maxretry = 5  
  10. banaction = firewallcmd-ipset  
  11. action = %(action_mwl)s  
  12. [sshd]  
  13. enabled = true  
  14. filter  = sshd  
  15. port    = 1090  
  16. action = %(action_mwl)s  
  17. logpath = /var/log/secure  
  1. # 重啟服務(wù)  
  2. $ systemctl restart fail2ban 

7從二次驗證鎖定中恢復(fù) 

  1. # 禁用特定用戶的二步驗證(無法訪問身份驗證器應(yīng)用程序)  
  2. $ sudo vim /etc/ssh/sshd_config  
  3. AuthenticationMethods publickey,keyboard-interactive  
  4. AuthenticationMethods publickey  
  5. # 重啟SSH服務(wù)  
  6. $ sudo systemctl restart ssh.service  

 

責(zé)任編輯:龐桂玉 來源: 良許Linux
相關(guān)推薦

2020-08-12 07:41:39

SQL 優(yōu)化語句

2021-03-12 10:01:24

JavaScript 前端表單驗證

2021-11-09 06:55:03

水印圖像開發(fā)

2021-07-14 09:00:00

JavaFX開發(fā)應(yīng)用

2011-01-10 14:41:26

2011-05-03 15:59:00

黑盒打印機

2022-04-01 09:00:00

Linux安全SSH

2021-08-18 07:29:41

密碼驗證 PAT

2022-01-08 20:04:20

攔截系統(tǒng)調(diào)用

2023-04-26 12:46:43

DockerSpringKubernetes

2022-12-07 08:42:35

2022-07-27 08:16:22

搜索引擎Lucene

2022-03-14 14:47:21

HarmonyOS操作系統(tǒng)鴻蒙

2011-02-22 13:46:27

微軟SQL.NET

2021-12-28 08:38:26

Linux 中斷喚醒系統(tǒng)Linux 系統(tǒng)

2021-02-26 11:54:38

MyBatis 插件接口

2017-07-07 11:01:04

Spark性能調(diào)優(yōu)

2021-07-01 09:31:50

MySQL SQL 語句數(shù)據(jù)庫

2024-04-02 08:58:13

2010-09-16 14:08:13

無線雙網(wǎng)
點贊
收藏

51CTO技術(shù)棧公眾號