Linux
Linux系统管理
Linux系统管理入门:网络管理
Linux系统管理入门:文件系统组成及常用命令详解
Linux系统管理入门:进程管理
Linux系统管理入门:用户、组与权限管理
Linux系统管理入门:磁盘管理
Linux介绍
ArchLinux安装NVIDIA驱动
Linux启用SSH登录二次验证
RedHat重置密码
Ubuntu安装显卡驱动
双网卡绑定
常用命令
开启ipv6协议栈
RedHat_Udev策略配置
本文档使用 MrDoc 发布
-
+
首页
Linux启用SSH登录二次验证
#### 1、安装PAM模块 ``` # 时间与客户端进行校验 $ ntpdate ntp.aliyun.com # 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 keyboard-interactive # 重启SSH服务 $ sudo systemctl restart sshd ``` #### 4、配置sudo 或 su - 二次验证 ``` # 保存并退出 $ sudo vim /etc/pam.d/su-l auth required pam_google_authenticator.so $ sudo vim /etc/pam.d/sudo-i auth required pam_google_authenticator.so # 重启SSH服务 $ sudo systemctl restart sshd ``` #### 5、手机安装Google身份验证器或Authy身份验证器 ```s 通过扫描第二步生成的二维码就可以获取动态验证码 ``` #### 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 ```
阿星
2024年1月21日 21:17
转发文档
收藏文档
上一篇
下一篇
手机扫码
复制链接
手机扫一扫转发分享
复制链接
Markdown文件
PDF文档(打印)
分享
链接
类型
密码
更新密码