SSH登录添加Google动态验证码


1.安装ntpdate用来定时校准时间

yum install ntpdate -y
安装完成以后,手动测试一下:sudo ntpdate 0.asia.pool.ntp.org
如果同步成功后,则会显示时间的差异

2.配置定时同步

每小时同步一次:
nano /etc/crontab
image

3.安装一些必要的组件

yum install -y git make gcc libtool pam-devel

4.编译安装谷歌验证器

git clone https://github.com/google/google-authenticator-libpam
cd google-authenticator-libpam/
./bootstrap.sh
./configure
make
make install
ln -s /usr/local/lib/security/pam_google_authenticator.so /usr/lib64/security/

5.配置SSH服务

nano /etc/ssh/sshd_config
修改以下配置:
ChallengeResponseAuthentication yes
UsePAM yes

6.重启SSH服务后配置PAM

配置 /etc/pam.d/sshd 文件
nano /etc/pam.d/sshd
将那行改为如图所示的内容
image
重载并重启ssh进程
原来的样子:
image

7.启用谷歌验证器

google-authenticator
image
手机下载Google Authenticator后扫描生成的这个二维码
然后命令行中输入手机上的动态验证码
会生成5个紧急救援码,记得保留
image
下面除了一个是否增加时间误差选择n以外,其余全部选择y
image

8.效果展示

image
第一次是需要输入手机上的动态验证码,第二次是需要输入正常的ssh密码。遇到问题,请查看日志文件 /var/log/secure。

9.出问题重新配置

命令行输入 google-authenticator 后重新配置即可

原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/289747.html

(0)
上一篇 2022年9月16日
下一篇 2022年9月16日

相关推荐

发表回复

登录后才能评论