4

登录centos添加google-authenticator

 6 months ago
source link: https://blog.51cto.com/landandan/7887149
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

安装google-authenticator

yum -y install google-authenticator
# 下载rpm包
https://download-ib01.fedoraproject.org/pub/epel/7/x86_64/Packages/g/google-authenticator-1.04-1.el7.x86_64.rpm
# 安装rpm包
rpm -Uvh google-authenticator-1.04-1.el7.x86_64.rpm

配置google-authenticator

!!需要给那个用户添加谷歌验证器,以下命令就在那个用户下执行

执行如下命令,用手机安装的google-authenticator扫描如下验证码

!!谁扫描的这个验证码,以后谁就可以用这个验证码登录系统,建议两个人扫描一下,做个备份,防止A同事离职后,还有B同事扛着

登录centos添加google-authenticator_rpm包

所有提问一路Y到底

登录centos添加google-authenticator_vim_02

配置ssh以使用Google可插入身份验证模块

修改pam.d/sshd配置

vim /etc/pam.d/sshd, 修改如下内容

# 注释掉密码要求,这里只想用google-authenticator应用程序生成的密钥和验证码
#auth       substack     password-auth


# 增加如下内容
auth required pam_google_authenticator.so nullok
auth required pam_permit.so

更改ssh配置以使其提示进行二次身份验证

vim /etc/ssh/sshd_config

# 注释打开
ChallengeResponseAuthentication yes 
# 注释掉
# ChallengeResponseAuthentication no 
# 文件底部添加这行 让ssh知道需要要求ssh密钥和验证码才能进入
AuthenticationMethods publickey,keyboard-interactive

重启sshd,使配置生效

systemctl restart sshd

jump连接验证

jump添加资产

登录centos添加google-authenticator_rpm包_03

可以添加多个账号

登录centos添加google-authenticator_vim_04
登录centos添加google-authenticator_vim_05
登录centos添加google-authenticator_验证码_06
登录centos添加google-authenticator_rpm包_07
登录centos添加google-authenticator_vim_08

注意的问题

短时间内第二次登录,可能会没有二次验证,直接登录到系统中,这种情况可以通过修改客户端的sshd配置

vim /etc/ssh/sshd_config

ClientAliveInterval 指定了服务器端向客户端发送消息的间隔,默认 0 不发送消息。

ClientAliveCountMax 服务器端发送消息后客户端没有响应的次数达到一定值,就自动断开

ClientAliveInterval 30  
ClientAliveCountMax 3

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK