实验环境:CentOS-7-x86_64-Minimal-1804
必须要关闭SELINUX
临时关闭SELinux,重启后失效:
setenforce 0
永久关闭,需要reboot重启后生效:
vim /etc/selinux/config
SELINUX=disabled
github下载
Google Authenticator:https://github.com/google/google-authenticator-libpam
编译和安装 ( Build & install )
安装前准备:autoconf、automake、PAM库等
sudo yum install autoconf automake libtool pam-devel
sudo ./bootstrap.sh
sudo ./configure
sudo make
sudo make install
sudo cp .libs/pam_google_authenticator.so /lib64/security/
设置PAM组件
编辑pam.d下的sshd文件,在第一行添加 保存
sudo vim /etc/pam.d/sshd
auth required pam_google_authenticator.so
设置SSH配置文件
编辑/etc/ssh/sshd_config
找到下行
ChallengeResponseAuthentication no
改为
ChallengeResponseAuthentication yes
登陆
用xshell登陆的话,使用Keyboard Interactive验证
先输入验证码Verification code:
再输入用户密码Password: