设为首页 收藏本站
查看: 1085|回复: 0

[经验分享] google的二次认证的搭建

[复制链接]
累计签到:67 天
连续签到:1 天
发表于 2018-10-22 17:10:31 | 显示全部楼层 |阅读模式
ssh二次认证登陆:

一般来说,使用ssh远程登录服务器,只需要输入账号和密码,显然这种方式不是很安全。为了安全着想,可以使用GoogleAuthenticator(谷歌身份验证器),以便在账号和密码之间再增加一个验证码,只有输入正确的验证码之后,再输入密码才能登录。这样就增强了ssh登录的安全性。账号、验证码、密码三者缺一个都不能登录,即使账号和密码正确,验证码错误,同样登录失败。其中,验证码是动态验证码,并且是通过手机客户端自动获取(默认每隔30秒失效一次)。好了,废话不多说了,下面记录下GoogleAuthenticator部署过程(Centos6系统下):

一、关闭selinux

[root@localhost ~]# grep disabled /etc/selinux/config

SELINUX=disabled


二、安装编辑包工具:

[root@localhost ~]# yum install wget gcc make pam-devel libpng-devel -y


下载repoforge第三方yum源及libpam-google-authenticator-1.0-source.tar.bz2、qrencode-3.4.4.tar.gz (以提前下载好了:链接:https://pan.baidu.com/s/1Wa-J3WHUZViEhQi4go6fpg
提取码:uaai)

[root@localhost ~]#  wget https://fukuchi.org/works/qrencode/qrencode-3.4.4.tar.gz

[root@localhost ~]# wget http://repository.it4i.cz/mirror ... 1.el6.rf.x86_64.rpm


wget http://repository.it4i.cz/mirror ... 1.el6.rf.x86_64.rpm

[root@localhost ~]# rpm -ivh rpmforge-release-0.5.3-1.el6.rf.x86_64.rpm

[root@localhost ~]# yum install mercurial -y

安装google authenticator PAM插件

[root@localhost ~]# tar xf libpam-google-authenticator-1.0-source.tar.bz2

[root@localhost ~]# cd libpam-google-authenticator-1.0

[root@localhost libpam-google-authenticator-1.0]# make && make install


安装QrenCode,此工具可以在Linux命令行下生成二维码


[root@localhost ~]# tar xf qrencode-3.4.4.tar.gz

[root@localhost ~]# cd qrencode-3.4.4

[root@localhost qrencode-3.4.4]# ./configure --prefix=/usr/

[root@localhost qrencode-3.4.4]# make && make install

三、配置ssh服务调用google authenticator PAM插件

[root@localhost ~]# cat /etc/pam.d/sshd  #在第一行(即auth required pam_sepermit.so的下一行)增加以下代码

auth       required     pam_google_authenticator.so  

[root@localhost ~]# vim /etc/ssh/sshd_config

......
ChallengeResponseAuthentication yes          #修改no为yes

[root@localhost ~]# /etc/init.d/sshd restart        重启ssh服务
Stopping sshd:                                             [  OK  ]
Starting sshd:                                             [  OK  ]

四、
使用google authenticator PAM插件为ssh登录账号生成动态验证码
注意:哪个账号需要动态验证码,请切换到该账号下操作。(可以在不同用户下执行这个命令以生成各自的二次验证码)

[root@localhost ~]# google-authenticator

Do you want authentication tokens to be time-based (y/n) y
https://www.google.com/chart?chs=200x200&chld=M|0&cht=qr&chl=otpauth://totp/root@localhost.localdomain%3Fsecret%3DCZE5FJIK4DTI5GL5   #这个链接只能在FQ条件下才能打开

Your new secret key is: CZE5FJIK4DTI5GL5   #如果在手机的谷歌身份验证器上不想通过"扫描条形码"的方式添加,就输入这个key,通过"手动输入验证码的方式"。账号就是服务器主机名
Your verification code is 156171
Your emergency scratch codes are:  #下面会生成5个紧急验证码(当无法获取动态验证码或验证码不能使用使用可以使用这5个)

                          #需要注意的是:这5个验证码用一个就会少一个!请保存好!
  39687224                    
  46596947
  14600735
  17283423
  27800842

Do you want me to update your "/root/.google_authenticator" file (y/n) y   #提示是否要更新验证文件,选择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, tokens are good for 30 seconds and 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. If you experience problems with poor
time synchronization, you can increase the window from its default
size of 1:30min to about 4min. Do you want to do so (y/n) y    #默认动态验证码在30秒内有效,由于客户端和服务器可能会存在时间差,可将时间增加到最长4分钟,是否要这么做:这里选择是n,继续默认30秒

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   #是否限制尝试次数,每30秒只能尝试最多3次,这里选择y进行限制


到此就可以使用了,但是手机得安装google身份验证器

怎么安装自行百度。


运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-625069-1-1.html 上篇帖子: pxe和kistart的自动化安装系统 下篇帖子: linux利用密钥远程登陆
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表