centos 6 SSH配置Google Authentication 验证

时间:2023-03-09 20:28:31
centos 6  SSH配置Google Authentication 验证

创建工作目录: mkdir google-authentication

1. 安装二维码生成依赖

#wget http://fukuchi.org/works/qrencode/qrencode-3.3.1.tar.gz

# tar xf qrencode-3.3.1.tar.gz

#cd qrencode-3.3.1

#./configure --prefix=/usr && make && make install

2. 安装Google-authenticator

#git clone https://github.com/google/google-authenticator.git

#cd google-authenticator/libpam/

#./bootstrap.sh && ./configure && make && make install

#执行google-authenticator命令配置

centos 6  SSH配置Google Authentication 验证

3. 配置sshd使用google-authenticator验证

3.1 复制pam动态库到默认加载目录

#cp /usr/local/lib/security/pam_google_authenticator.so /lib64/security/

3.2 在/etc/pam.d/sshd中添加使用google_authenticator,首行添加

auth       required pam_google_authenticator.so

3.3 编辑/etc/ssh/sshd_config

ChallengeResponseAuthentication yes

3.4 重器sshd: service sshd restart

4. 手机下载Google 身份验证器,输入第2步中生成的secret key和用户名,配置好,然后就会每30s生成一个验证码。

我这里是设置的root,因为我第2步是在root家目录下设置的google-authenticator,如果是其它用户,请切换到其它用户再执行google-authenticator命令生成秘钥。

5. 在其它机器上登录这台服务器:就会要求先输入验证码,这个时候,在手机上查看验证码,输入,然后再输入用户密码,都验证通过,才可以登录。

centos 6  SSH配置Google Authentication 验证