CentOS安装所需组件:
yum -y install mercurial pam-devel
安装Google Authenticator:
#https://www.haiyun.me
wget --no-check-certificate https://google-authenticator.googlecode.com/files/libpam-google-authenticator-1.0-source.tar.bz2
tar jxvf libpam-google-authenticator-1.0-source.tar.bz2
cd libpam-google-authenticator-1.0
make
make install
SSH登录时调用google-authenticator模块,编辑:
/etc/pam.d/sshd
第一行添加:
auth required pam_google_authenticator.so
修改SSH配置文件:
vim /etc/ssh/sshd_config
添加或修改以下内容:
ChallengeResponseAuthentication yes
UsePAM yes
重启SSH:
/etc/init.d/sshd restart
生成google-authenticator配置,运行:
google-authenticator
Do you want authentication tokens to be time-based (y/n) y
https://www.google.com/chart?chs=200x200&chld=M|0&cht=qr&chl=otpauth://totp/root@node1.www.haiyun.me%3Fsecret%3DABEXG5K6CVB56BXY
#此网址为生成的二维码,客户端扫描
Your new secret key is: www.haiyun.me
Your verification code is 582849
Your emergency scratch codes are:
30776626
14200155
80795568
23936997
21919909
#上面几行数字为应急码
Do you want me to update your "/root/.google_authenticator" file (y/n) y
#更新配置文件
Do you want to disallow multiple uses of the same authentication
token? This restricts you to one login about every 30s, but it increases
your chances to notice or even prevent man-in-the-middle attacks (y/n) y
#禁止一个口令多用
By default, tokens are good for 30 seconds and in order to compensate for
possible time-skew between the client and the server, we allow an extra
token before and after the current time. If you experience problems with poor
time synchronization, you can increase the window from its default
size of 1:30min to about 4min. Do you want to do so (y/n) n
#客户端与服务器时间误差
If the computer that you are logging into isn't hardened against brute-force
login attempts, you can enable rate-limiting for the authentication module.
By default, this limits attackers to no more than 3 login attempts every 30s.
Do you want to enable rate-limiting (y/n) y
#次数限制
Android安装google-authenticator客户端,扫描添加上方网址的二维码,以后在登录服务器时输入账号密码的同时还需输入google-authenticator即时生成的验证码才能登录。
ssh www.haiyun.me
Verification code:
Password:
标签:centos, ssh, 网络安全, ssh安全设置, 服务器安装, 使用Google Authenticator为ssh验证, Google Authenticator, ssh二次验证
google在国内老被封,这样不会有影响?
客户端即时生成验证码无需连接google服务器。