背景
今天偶然发现作为外网接入网关的服务器一直在被各种IP尝试登陆,如果一旦被爆破成功那么我接入的设备和其他服务器就可能被轻易的攻破。
于是想着为这台服务器的SSH添加一个两步验证来提高安全性。
过程
组件准备
安装支持库
1
|
yum -y install autoconf automake libtool pam-devel
|
编译安装二维码支持
1
2
3
4
5
6
|
git clone https://github.com/fukuchi/libqrencode.git
cd libqrencode
./autogen.sh
./configure
make -j3
make install
|
编译安装google-authenticator
1
2
3
4
5
6
|
git clone https://github.com/google/google-authenticator-libpam.git
cd google-authenticator-libpam
./bootstrap.sh
./configure
make -j3
make install
|
配置修改
修改PAM配置/etc/pam.d/sshd (以下配置添加至首行则是先输入Verification Code)
1
2
3
|
auth required pam_sepermit.so
auth substack password-auth
auth required /usr/local/lib/security/pam_google_authenticator.so
|
修改sshd配置/etc/ssh/sshd_config
1
|
ChallengeResponseAuthentication yes
|
重启sshd
systemctl restart sshd.service
Google Authenticator配置
直接运行命令
然后用手机上的Authenticator类的应用扫描一下,保存一下密钥就行了。
后面的一些安全配置我默认全部选择yes来提高安全性。