使用谷歌身份验证器增强SSH安全!!!!

使用谷歌身份验证器增强SSH安全

2016年06月12日 10:01:51 dongsong1117 阅读数:7922 标签: linuxssh谷歌身份验证器动态口令更多

个人分类: Linux运维

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/dongsong1117/article/details/51644148

一般大家都是使用账号和密码远程SSH登录管理服务器。但SSH账号和密码很容易泄露,或者经常遭遇暴力破解。咨询过前同事赛赛,他们目前使用了谷歌身份验证器。查看了谷歌身份验证器的github网址和其它网上文档,重新整理归纳。

谷歌身份验证器生成的是动态验证码,默认30秒更新。修改配置,SSH登录必须在输入密码之前输入动态验证码。即使账号和密码泄露,验证码输入错误,仍然无法登录。苹果或者安卓手机端可以安装身份验证器App读取验证码。

1.禁用并关闭selinux

sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
setenforce 0
  • 1
  • 2

2.安装依赖软件包

yum -y install gcc make pam-devel libpng-devel libtool wget git
  • 1

3.添加阿里云epel源 
* RHEL 6/CentOS 6系列

wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo
  • 1
  • RHEL 7/CentOS 7系列
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
  • 1

4.安装Qrencode,谷歌身份验证器需要调用该程序以便终端生成并显示二维码

yum -y install qrencode
  • 1

5.安装谷歌身份验证器

mkdir -p /App/src
cd /App/src
git clone https://github.com/google/google-authenticator.git
cd google-authenticator/libpam/
./bootstrap.sh
./configure
make
make install
cp .libs/pam_google_authenticator.so /lib64/security/
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

6./etc/pam.d/sshd第一行后添加谷歌身份验证器PAM模块配置

auth       required     pam_google_authenticator.so
  • 1

7.修改SSH服务配置/etc/ssh/sshd_config

sed -i 's#^ChallengeResponseAuthentication no#ChallengeResponseAuthentication yes#' /etc/ssh/sshd_config
  • 1

8.重启SSH服务 
* RHEL 6/CentOS 6系列

service sshd restart
  • 1
  • RHEL 7/CentOS 7系列
systemctl restart sshd.service
  • 1

9.终端切换至需要二次验证的系统账户后运行验证器程序google-authenticator,遇到(y/n)可以都输入y,为需要远程SSH登录的每个用户生成动态口令

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/songsong@localhost.localdomain%3Fsecret%3DX3PYDDGPI4BF3DMIVTZ33IRQI4%26issuer%3Dlocalhost.localdomain
二维码
Your new secret key is: X3PYDDGPI4BF3DMIVTZ33IRQI4
Your verification code is 318806
Your emergency scratch codes are:
  34181847
  33327793
  54307163
  36901756
  21117069

Do you want me to update your "/home/songsong/.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. 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 +-1min (window size of 3) to about +-4min (window size of
17 acceptable tokens).
Do you want to do so? (y/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
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30

10.苹果手机打开App Store搜索Google Authenticator,安卓手机打开应用商店搜索身份验证器,安装对应App

11.手机打开安装的App后点击开始设置

谷歌身份验证器

12.点击扫描条形码,扫描终端显示的二维码。需要安装专用条码扫描器,微信和QQ的扫描二维码不起作用

谷歌身份验证器

13.修改SecureCRT连接属性,右键选择已有主机连接的Properties,在新弹窗点选SSH2,将 Authentication选项中的Keyboard Interactive顺序调整至首行

修改SecureCRT连接属性


终端运行验证器程序google-authenticator内容说明:

Do you want authentication tokens to be time-based (y/n)
  • 1

输入y基于时间方式生成验证口令,输入n使用计数器方式生成验证口令。

https://www.google.com/chart?chs=200x200&chld=M|0&cht=qr&chl=otpauth://totp/songsong@localhost.localdomain%3Fsecret%3DX3PYDDGPI4BF3DMIVTZ33IRQI4%26issuer%3Dlocalhost.localdomain
  • 1

显示二维码图片的地址,需要设法能够访问到谷歌,可以使用翻墙,或者寻找暂未被中国长城防火墙屏蔽的谷歌公网IP地址,然后修改系统hosts文件地址映射。

二维码
  • 1

若未安装Qrencode,则不会显示二维码。

Your new secret key is: X3PYDDGPI4BF3DMIVTZ33IRQI4
  • 1

若未显示二维码,生成的谷歌二维码图片地址亦无法访问,则进入手机端身份验证器设置后点选输入提供的密钥,填写运行google-authenticator程序的账户名及符号:之后的密钥也能达到同样的效果。

谷歌身份验证器

Your verification code is 318806
  • 1

临时生成的6位数字验证码,默认30秒到期。

Your emergency scratch codes are:
  34181847
  33327793
  54307163
  36901756
  21117069
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

生成的5组应急备用验证码,每个验证码只能使用一次,使用后立即失效。当多次使用手机App端显示的验证码无效时使用,保存备用。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值