我们可以通过安装Google身份验证器登录服务器,这样即使密码泄露没有验证码别人也进入不了服务器
环境准备
1.安装需要的软件
yum -y install gcc make pam-devel libpng-devel libtool wget git
2.下载google-authenticator-libpam
git https://github.com/google/google-authenticator-libpam.git
3.安装编译
cd google-authenticator-libpam/ ./bootstrap.sh
./configure && make && make install
编译成功会在目录生成文件
ll /usr/local/lib/security/pam_google_authenticator.so
复制文件到lib64
cp /usr/local/lib/security/pam_google_authenticator.so /lib64/security/
4.配置/etc/pam.d/sshd
添加下图内容后
auth required pam_google_authenticator.so
5.更改sshd配置文件/etc/ssh/sshd_config
6.重启sshd
systemctl restart sshd
7.切换到需要验证的用户如root用户
google-authenticator
使用手机google身份验证器扫描二维码进行登录
8.xshell配置
9.登录服务器
输入google身份验证码
输入系统密码
登录成功!