Google Authenticator SSH public key 两步验证

  • A+
所属分类:安全

为了增强安全需要两步验证(two-factor authentication)。 本文说说如何使用Google Authenticator  + SSH public key 等服务器进行两步验证。

依赖关系

google authenticator

需要先安装EPEL源。或者源码安装,如下:

google-authenticator生成密钥信息

生成的5个一次性紧急验证码,用于紧急情况下,使用过一次后该验证码即失效了。

配置ssh使用google authenticator

添加一行并注释一行。

重启sshd服务。

可能会报如下错误:

Starting sshd: /etc/ssh/sshd_config: line 89: Bad configuration option: AuthenticationMethods
/etc/ssh/sshd_config: terminating, 1 bad configuration options

是由于OpenSSH 版本6.2以上才支持AuthenticationMethods。需要改成下面的参数:

RequiredAuthentications2 publickey,keyboard-interactive

手机端安装Google authenticator

Andorid版   https://play.google.com/store/apps/details?id=com.google.android.apps.authenticator2

iOS版   https://itunes.apple.com/cn/app/google-authenticator/id388497605

手机端打开google 身份验证器,扫二维码或者输入secret key

也可以安装chrome的google authenticator扩展。

ssh登录服务器就会提示你输入Verification code:

secureCRT设置

Google Authenticator

keyboard interactive需要放在第一位。

Google Authenticator

注意:使用password + google authenticator,如果使用公钥登录的话,会跳过google authenticator验证直接登录服务器的。

weinxin
微信公众号
扫一扫关注运维生存时间公众号,获取最新技术文章~

评论已关闭!

目前评论:1   其中:访客  1   博主  0

    • ophusky 0

      我按如上配置,第一步弹出Verification code输入框,第二步弹出的是密码输入框,而不是公钥验证,是怎么回事呢,不是禁止了密码验证码?