Google
Authenticator是一个动态验证码程序,兼容各种智能手机平板设备,可以用来做各种帐号的二次验证,增加帐号的安全性。SSH是Linux系统的最重要防线之一,为了防止密码泄露或者被爆破,可以使用Google
Authenticator来做二次验证,使用方法也很简单。
先说说Debian下的安装和设置:
Debian 7.3默认源里面还没有相关的deb程序,不过sid源里已经有了。
后续补充:Debian 8以上系统源已自带libpam-google-authenticator,无需另外下载,直接apt安装即可。
先下载libpam-google-authenticator
wget -c http://ftp.us.debian.org/debian/pool/main/g/google-authenticator/libpam-google-authenticator_20130529-2_amd64.deb
先安装libqrencode3
apt-get install libqrencode3 -y
再安装下载的deb
dpkg -i libpam-google-authenticator_20130529-2_amd64.deb
运行Google Authenticator向导
google-authenticator
会有几个问题出来,选择y即可。
然后中间会有一个二维码和一些应急验证码,记录下应急验证码。
如果ssh客户端不能正确显示二维码,复制上面google网站的连接在浏览器中打开就可以显示对应的二维码。
启动移动设备上的Google Authenticator扫描二维码即可完成设置。
接下来设置ssh验证。
nano /etc/pam.d/sshd
再结尾添加一行
auth required pam_google_authenticator.so
继续修改
nano /etc/ssh/sshd_config
修改ChallengeResponseAuthentication为yes
ChallengeResponseAuthentication yes
重启ssh服务
/etc/init.d/ssh restart
重新连接ssh的时候除了输入密码的提示以外,还会提示输入Verification code,这时只要输入移动设备上Google Authenticator的验证码即可登录。
接下来说说CentOS下的安装和设置:
安装编译需要的编译工具
yum install gcc gcc++ pam-devel subversion python-devel git
获取源码
git clone https://code.google.com/p/google-authenticator/
编译
cd google-authenticator/libpam/
make && make install
运行Google Authenticator向导
google-authenticator
会有几个问题出来,选择y即可。
然后中间会有一些应急验证码出现,记录下应急验证码。
复制上面google网站的连接在浏览器中打开就可以显示对应的二维码。
启动移动设备上的Google Authenticator扫描二维码即可完成设置。
接下来设置ssh验证。
nano /etc/pam.d/sshd
再结尾添加一行
auth required pam_google_authenticator.so
继续修改
nano /etc/ssh/sshd_config
修改ChallengeResponseAuthentication为yes
ChallengeResponseAuthentication yes
重启ssh服务
service sshd restart
Google Authenticator使用的时候无需联网,在移动设备无网络的情况下也可以使用。默认每30秒变换一组验证码,需要注意的是,移动设备的时间一定不能跟标准时间相差太多,否则可能导致无法显示正确的验证码,可能的情况下最好设置网络对时。
使用SecureCRT客户端的话,默认情况下会不支持这种验证方式,只要在会话选项中修改SSH—-Authentication,设置为Keyboard Interactive即可,其他的选项包括Password都要设置在Keyboard Interactive之下或者直接去掉。
另外,使用Publickey免密码登录方式来登录ssh的话,不支持使用Google Authenticator验证,必须是密码验证的登录方式才支持。
No comments:
Post a Comment