开发者社区> 问答> 正文

#技塑人生# 专题:软件分享 - Linux SSH登录建立双因子验证机制

专题:软件分享 - Linux SSH登录建立双因子验证机制(谷歌身份验证器 Google Authenticator)
阿里云技术服务团队:蒋金城


ssh public key登录还不够安全,这里介绍一个新的软件Google Authenticator双因子验证模块,该模块可以在连接到SSH服务器时,输入一个随机的一次性密码(TOTP)验证码。需要从智能手机或个人电脑输入这个验证码。

实现需求:
Linux SSH登录使用GoogleAuthenticator双因子验证模块

实现软件:
Google Authenticator:谷歌身份验证器(GoogleAuthenticator)是一种开源模块,实施了由谷歌开发的一次性通行码(TOTP)验证令牌。除了PAM(可插入验证模块)外,它还支持几种移动平台。这些一次性通行码是使用OATH(开放验证组织)制定的开放标准生成的。

测试系统:
阿里云Centos 6.5 64位(其他版本系统未测试,各位网友可以亲测)

安装配置:

1.安装谷歌身份验证器模块:

登录需要安装双因子验证机制的主机,安装下列PAM库以及PAM模块与谷歌身份验证器模块顺利协同运行所需要的开发库。

Red Hat, CentOS, Fedora 系统需要安装pam-devel 包:
安装命令:
# yum installpam-devel make gcc-c++ wget

Ubuntu,Linux Mint,Debian 系统需要安装‘libpam0g-dev包:
安装命令:
# apt-getinstall libpam0g-dev make gcc-c++ wget

谷歌身份验证器模块:
# wgetcache.ali.dagaiba.com/google-authenticator/libpam-google-authenticator-1.0-source.tar.bz2
# tar -xvflibpam-google-authenticator-1.0-source.tar.bz2
# cdlibpam-google-authenticator-1.0
# make
# make install
安装过程截图:





运行google-authenticator开始生成密钥信息,一下一直Y就可以,出现错误,重新运行命令google-authenticator。




附:英文解释:
Do you want authentication tokens to betime-based (y/n) y
做你想做的认证令牌是基于时间的吗?

Do you want me to update your"/root/.google_authenticator" file (y/n) y
你希望我更新你的“/root/.google_authenticator”文件吗(y/n)?

Do you want to disallow multiple uses ofthe 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-middleattacks (y/n) y
你希望禁止多次使用同一个验证令牌吗?这限制你每次登录的时间大约是30秒,但是这加大了发现或甚至防止中间人攻击的可能性(y/n)?y

By default, tokens are good for 30 secondsand in order to compensate for possible time-skew between the client and theserver, we allow an extra token before and after the current time. If youexperience problems with poor time synchronization, you can increase the windowfrom its default size of 1:30min to about 4min. Do you want to do so (y/n) y
默认情况下,令牌保持30秒有效;为了补偿客户机与服务器之间可能存在的时滞,我们允许在当前时间前后有一个额外令牌。如果你在时间同步方面遇到了问题,可以将窗口从默认大小即1分30秒加大到约4分。你希望这么做吗(y/n)?

If the computer that you are logging intoisn't hardened against brute-force login attempts, you can enable rate-limitingfor the authentication module.By default, this limits attackers to no more than3 login attempts every 30s.Do you want to enable rate-limiting (y/n) y
如果你登录的那台计算机没有经过固化,以防范运用蛮力的登录企图,可以对验证模块启用尝试次数限制。默认情况下,这限制攻击者每30秒试图登录的次数只有3次。你希望启用尝试次数限制吗(y/n)?

2.配置SSH使用谷歌身份验证器模块:
编辑 PAM配置文件“/etc/pam.d/sshd”,把下面这行添加到该文件的顶部
auth       required     pam_google_authenticator.so


编辑SSH配置文件“/etc/ssh/sshd_config”,找到下面内容的这一行:
ChallengeResponseAuthenticationno
将 no 更改成 yes 。
ChallengeResponseAuthenticationyes

最后,重启SSH服务,以便让新的变更生效。
命令:
/etc/init.d/sshdrestart
3.安装、配置谷歌身份验证器应用程序:
安装就不多讲了,安装个GooglePlay,在Google应用中去搜索:Google Authenticator 安装即可。
配置谷歌身份验证器:
打开GoogleAuthenticator应用。
点击“开始设置”



点击“输入提供的密钥”

在“输入账户名称”这个自己定义一个名字,在“输入您的密钥”就输入之前生成的secret key。

在打开GoogleAuthenticator就是上面样子。
4.测试SSH登录:
比较直观的测试就是从一台linux主机访问这台主机,ssh-v ip地址。



阿里云官方微博地址:http://weibo.com/1644971875/BbYVA4ajn

展开
收起
qiujin2012 2014-07-03 22:56:26 14824 0
2 条回答
写回答
取消 提交回答
  • 优秀文章-欢迎进行技术分享,感谢你的支持!
    2014-07-04 19:16:36
    赞同 展开评论 打赏
  • 收藏了……周末好好研究下!谢谢分享!
    2014-07-04 08:41:47
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
Alibaba Cloud Linux 3 发布 立即下载
ECS系统指南之Linux系统诊断 立即下载
ECS运维指南 之 Linux系统诊断 立即下载