APP下载
报价宝  ›  科技  › 

通过手机金钥的动态密码加强SSH登入安全性

报价宝 来源:baojiabao.com 发布时间:2019-10-07 18:52:00 10月02日更新
报价宝综合消息通过手机金钥的动态密码加强SSH登入安全性

功能介绍:

以前介绍了使用公钥形式登入跳板机,但是想想每次都得将公钥拷给别人好像有点麻烦,并且一换电脑,公钥也要重新设定。如果用在网咖什么的感觉也不是很安全。于是想到了使用Google身份验证器来验证。

Google身份验证器功能就是通过手机上面30秒一变的随机密码,来验证服务器。大家可以想象成是银行那类似于小U盘一样的东西,密码30秒变一次。这样也保证了登入的安全性。

环境:

CentOS 6.5

基础元件安装:

yum -y install wget gcc make pam-devel libpng-devel

一、安装qrencode

在Linux上,有一个名为 QrenCode 的命令列工具可以很容易帮我们生成二维码,google authenticator命令列生成二维码就是呼叫它。

wget http://fukuchi.org/works/qrencode/qrencode-3.3.1.tar.gz

tar zxf qrencode-3.3.1.tar.gz

cd qrencode-3.3.1

./configure --prefix=/usr && make && make install

二、安装google authenticator PAM外挂

wget http://google-authenticator.googlecode.com/files/libpam-google-authenticator-1.0-source.tar.bz2

tar jxf libpam-google-authenticator-1.0-source.tar.bz2

cd libpam-google-authenticator-1.0

make && make install

三、配置google authenticator

首先需要切换到对应的使用者,如果想多使用者都使用这种方式登入,需要先切换到对应的使用者,再执行 google-authenticator 命令,程式会问你Do you want authentication tokens to be time-based (y/n),大意是基于时间生成验证码(及TOTP),这里选择y。

这个二维码自然是给 Google Authenticator(手机安装搜寻 Google Authenticator,或者叫Google身份验证器) 应用程序来扫描的。还可以照二维码下面的文字金钥手工输入。当 Google Authenticator 识别了这个账号之后,验证器就配置好了。在文字金钥下面还提供了几个应急码,为防止手机丢了等情况下所用的,可以妥善保管。

这时 Google Authenticator 虽然运行了,但是相关设定还没有储存,程式会问你 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)

大意是问是否开启时间容错以防止客户端与服务器时间相差太大导致认证失败。这个可以根据实际情况来。我的ipad时间很准(与网络同步的),所以答 n,如果一些平板电脑不怎么连网的,可以答 y 以防止时间错误导致认证失败。再一个问题是

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。

问题答完了,家目录中多出一个 .google_authenticator 档案(预设许可权为 400),这时客户端与服务端已经配套起来了,以后不用再执行 google-authenticator 命令了,否则会重新生成一组密码。

四、配置SSH验证

此时虽然 Google Authenticator 已经配置好了,但是并没有任何程式会去呼叫它。所以需要设定 SSH 登入的时候去通过它验证。

开启 /etc/pam.d/sshd 档案,新增

auth required pam_google_authenticator.so

这一行,储存。再开启 /etc/ssh/sshd_config 档案,找到

ChallengeResponseAuthentication no

把它改成

ChallengeResponseAuthentication yes

并储存。最后,输入

service ssh restart

来重启 SSH 服务以应用新的配置。

这时候再用 SSH 登入的话就会这样了:

这样就成功了。

五、设定客户端登陆方式

将上面的二维码,或者产生的金钥输入到手机Google Authenticator客户端(这个网上很多,商城也一般都,就叫google身份验证器)

使用secureCRT的使用者:

使用XShell的使用者:

设定好后敲回车键登入,此时出现要求输入code这个就是手机上那个30秒一变的验证码;

然后要求输入密码,这个就是使用者的真正密码

确保手机时间和服务器时间基本一致。如果输入都正确即可登入成功了。

文章标签: 报价宝 降噪耳机价格 耳机价格 红米手机价格 华为手机价格 小米手机价格 电视机价格 笔记本电脑价格 笔记本价格 汽车价格 数码相机价格 笔记本电脑价格 小米手机价格 红米手机价格 耳机价格