默认情况下,令牌只在30秒内有效,由于客户端和服务器时间不完全一致的因素,可以将时间窗口加大到最长4分钟,是否要这么做:
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秒只能尝试最多3次:
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
密钥生成好之后,下面修改PAM中关于ssh的配置,编辑/etc/pam.d/sshd文件:
# vim /etc/pam.d/sshd
增加一行:
auth required pam_google_authenticator.so
接下来再修改ssh的配置文件,编辑/etc/ssh/sshd_config文件:
# vim /etc/ssh/sshd_config
将ChallengeResponseAuthentication no修改为ChallengeResponseAuthentication yes
然后重新启动ssh服务:
当再次使用jss用户以SSH方式登录时,就会提示输出验证码:
[root@mysqldb02 ~]# ssh jss@192.168.30.249
Verification code:
那么,验证码从哪里来呢,朋友,您这算是问到点儿上了。拿出你的手机,安装一款名叫:Google身份验证器的应用。在打开的应用界面中新增帐户,然后会出现两个选择:扫描条形码(二维码),或者选择输出提供的密钥,任选其一即可。
有同学可能会问,这两项信息从哪里来呢,同学,请你再仔细看下,执行google-authenticator命令后首先输出的信息,那个HTTP的网址,打开你就会发现,原来它是个图片二维码,扫描即可。若网址打不开也没关系,选择密钥就是了嘛。
帐户添加完成后,您应该就能在手机上看到它生成的验证码了,先输入验证码,然后再输入密码,只有验证码和密码都输入正确,才能正常登录。
Password:
Last login: Tue Jan 14 10:14:33 2014 from 192.168.30.246
注意哟,输入验证码的时间最长只有30秒钟,超时之后该验证码就失效,需要到手机端获取新的验证码才行。
本文永久更新链接地址:http://www.linuxidc.com/Linux/2014-05/101791.htm
