转载自:https://mp.weixin.qq.com/s/ssuhFbfaHxxzGmLg6Y2MjA

目前来说,二次验证(这里就不做过多解释了)是比较常用的安全手段,通过设置二次验证(谷歌或其他工具),就可以有效的避免账户密码的泄露导致的安全问题。因为,每次登陆前都需要获取一次性验证码,如果没有验证码的话就无法成功登陆。

1、安装 PAM 模块

# 时间与客户端进行校验
$ ntpdate pool.ntp.org # Ubuntu
$ sudo apt install -y libpam-google-authenticator # CentOS7
$ yum install -y epel-release
$ yum install -y google-authenticator

2、生成二次验证代码

# 生成验证码, 哪个账号需要动态验证码,请切换到该账号下操作

# -t: 使用 TOTP 验证
# -f: 将配置保存到 ~/.google_authenticator 文件里面
# -d: 不允许重复使用以前使用的令牌
# -w 3: 使用令牌进行身份验证以进行时钟偏移
# -e 10: 生成 10 个紧急备用代码
# -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

3、配置 SSH 服务启用两步验证

# 启用两步验证
$ sudo vim /etc/pam.d/sshd
# @include common-auth # 将禁用密码身份验证
auth required pam_google_authenticator.so # 禁用密码验证 # 修改SSH配置文件
$ sudo vim /etc/ssh/sshd_config
Port 1090
ChallengeResponseAuthentication yes
PubkeyAuthentication yes
PasswordAuthentication no
AuthenticationMethods publickey,keyboard-interactive # 重启SSH服务
$ sudo systemctl restart ssh.service

4、配置 sudo 二次验证

# 保存并退出
$ sudo vim /etc/pam.d/common-auth
auth required pam_google_authenticator.so # 重启SSH服务
$ sudo systemctl restart ssh.service

5、手机安装 Google 身份验证器

  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 # 重启服务
$ systemctl restart fail2ban

7、从二次验证锁定中恢复

# 禁用特定用户的二步验证(无法访问身份验证器应用程序)
$ sudo vim /etc/ssh/sshd_config
AuthenticationMethods publickey,keyboard-interactive
AuthenticationMethods publickey # 重启SSH服务
$ sudo systemctl restart ssh.service

最新文章

  1. Python数据库迁移脚本(终极版)
  2. 使用sql语句创建修改SQL Server标识列(即自动增长列)
  3. SQL SERVER事务处理
  4. Fisher information matrix笔记
  5. hazelcast的坑爹事
  6. C# Convert an enum to other type of enum
  7. rabibtMQ安装及集群配置-linux
  8. MySQL Replicationation基础
  9. cygwin下配置alias
  10. python只re模块
  11. JSP之JSTL_functions
  12. Python爬虫 - 爬取百度html代码前200行
  13. DDD实战进阶第一波(九):开发一般业务的大健康行业直销系统(实现经销商上下文仓储与领域逻辑)
  14. pyhive 连接 Hive 时错误
  15. vue动态绑定background:url绑不上的问题
  16. linux下安装SlickEdit
  17. (转载)Linux之虚拟机 rehl7的ip
  18. linux下命令学习
  19. matlab一些函数
  20. 如何设置eclipse不同的workspace共享配置

热门文章

  1. eclipse调用MySQL数据库的方法
  2. springboot中配置skywalking请求日志
  3. 爬虫部署 Gerapy 安装(centos 8)演示
  4. Git上传仓库
  5. Linux中安装JDK详细步骤
  6. HashTable集合和练习题_计算一个字符串中每一个字符出现的次数
  7. net core天马行空系列-各大数据库快速批量插入数据方法汇总
  8. Odoo14 TypeError: Cannot read property 'classList' of undefined
  9. 使用jmh框架进行benchmark测试
  10. 美女 Committer 手把手教你部署 Apache DolphinScheduler 单机版