CentOS 7安装Google Authenticator进行登陆二次验证

1|01、安装依赖

yum install -y epel-* mercurial autoconf automake libtool pam-devel

2|02、安装google-authenticator

yum install -y google-authenticator

3|04、PAM组件配置google-authenticator

vim /etc/pam.d/sshd auth required pam_google_authenticator.so # 或者 echo "auth required pam_google_authenticator.so" >>/etc/pam.d/sshd

4|05、修改SSH配置

vim /etc/ssh/sshd_config # ChallengeResponseAuthentication no # 改为 ChallengeResponseAuthentication yes # 或者 sed -i 's/ChallengeResponseAuthentication no/ChallengeResponseAuthentication yes/g' /etc/ssh/sshd_config

5|06、重启SSH服务

systemctl restart sshd.service

6|07、生成google-authenticator配置

google-authenticator Do you want authentication tokens to be time-based (y/n) y 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/root@demo%3Fsecret%3DXQ2WB526GLPJ7SI64Z3RZISOEE%26issuer%3Ddemo 这里会有一个二维码,需要在手机上下载`googleauthenticator`APP扫码绑定 安卓 IOS手机都可以在应用商店搜索安装 Your new secret key is: XQ2WB526GLPJ7SI64Z3RZISOEE Your verification code is 917990 Your emergency scratch codes are: 42623319 72314571 14476695 95764389 38976136 Do you want me to update your "/root/.google_authenticator" file? (y/n) y Do you want to disallow multiple uses of the same authentication token? This restricts you to one login about every 30s, but it increases your chances to notice or even prevent man-in-the-middle attacks (y/n) y By default, a new token is generated every 30 seconds by the mobile app. In order to compensate for possible time-skew between the client and the server, we allow an extra token before and after the current time. This allows for a time skew of up to 30 seconds between authentication server and client. If you experience problems with poor time synchronization, you can increase the window from its default size of 3 permitted codes (one previous code, the current code, the next code) to 17 permitted codes (the 8 previous codes, the current code, and the 8 next codes). This will permit for a time skew of up to 4 minutes between client and server. Do you want to do so? (y/n) y If the computer that you are logging into isn't hardened against brute-force login attempts, you can enable rate-limiting for the authentication module. By default, this limits attackers to no more than 3 login attempts every 30s. Do you want to enable rate-limiting? (y/n) y

7|08、调整XShell登陆配置

XShell登陆需要更改为Keyboard Interactive验证登陆。

img

8|09、登陆时需要结合手机APP上的验证码才可以登陆

登陆的时候选择Keyboard Interactive验证登陆。

然后输入服务器密码

输入手机APP上的验证码

登陆成功

因为手机上的 google authenticator这个APP是根据时间来生成随机验证码的,所以必须保证服务器上的时间和手机时间一致,不然可能会出现无法登陆的情况!

建议安装时间同步服务器或者安装一个自动同步时间的软件(例如:chrony)

yum install -y chrony systemctl enable chronyd systemctl start chronyd

__EOF__

本文作者StaryJie
本文链接https://www.cnblogs.com/jie-fang/p/13445777.html
关于博主:评论和私信会在第一时间回复。或者直接私信我。
版权声明:本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
声援博主:如果您觉得文章对您有帮助,可以点击文章右下角推荐一下。您的鼓励是博主的最大动力!
posted @   StaryJie  阅读(1591)  评论(0编辑  收藏  举报
编辑推荐:
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
阅读排行:
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 单元测试从入门到精通
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律
点击右上角即可分享
微信分享提示