利用google-authenticator给SSH加密

简介:

所需软件:

google-authenticator

qrencode( 非必须,其主要用于在终端下生成二维码用)


以下根据自己的手机系统选择

Google Authenticator Android 

https://play.google.com/store/apps/details?id=com.google.android.apps.authenticator2&hl=en_GB


Google Authenticator iOS 

https://itunes.apple.com/gb/app/google-authenticator/id388497605?mt=8


Authenticator for Windows Phone

http://www.windowsphone.com/en-gb/store/app/authenticator/e7994dbc-2336-4950-91ba-ca22d653759b


google-authenticator下载地址如下:

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


qrencode下载地址如下:

http://fukuchi.org/works/qrencode/qrencode-3.4.3.tar.gz


安装:

google-authenticator依赖于pam-devel所以这个要安装.

1
yum -y  install  wget gcc  make  pam-devel libpng-devel
1
2
3
4
tar  xvzf libpam-google-authenticator-1.0- source . tar .bz2
cd  libpam-google-authenticator-1.0
make
make  install
1
2
3
4
5
  tar  xvzf qrencode-3.4.3. tar .gz
cd  qrencode-3.4.3
. /configure
make 
make  install


安装完成之后运行google-authenticator命令

首先会提示你,是否要基于时间生成令牌,选择Y,然后它会生成密钥,以及紧急状态使用的验证码(有5个,谨当无法获取验证


码时使用,注意这些紧急验证码用一次就少一个的哟,所以这几个紧急验证码一定要保存好

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
31
32
33
34
[root@ test /] # 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 @openmeeting
 
%3Fsecret%3D5WYP6I7SCT5P25GQ
Your new secret key is: 5WYP6I7SCT5P25GQ
Your verification code is 224400
Your emergency scratch codes are:
   95939927
   38607970
   93250589
   88706290
   92430531
你是否要更新验证文件 选择Y
Do you want me to update your  "/root/.google_authenticator"  file  (y /n ) y
 
提示是否禁止多次使用相同的令牌登录:选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
 
默认令牌只在30秒有效.由于客户端和服务器时间不完全一致.可以将时间窗口加大到最长4分钟,是否要这么做:选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 ) y
 
是否限制尝试次数,每30秒只能尝试最多3次:
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
[root@ test  /] #

密钥生成好之后.下面修改PAM中关于ssh的配置,编辑/etc/pam.d/sshd文件

在第一行增加:

1
auth    required        pam_google_authenticator.so

接下来再修改ssh的配置文件,编辑/etc/ssh/sshd_config文件

将ChallengeResponseAuthentication no修改为ChallengeResponseAuthentication yes

修改完成之后重启SSH服务,下次登录就要输入动态验证码:


现在在手机端安装Google Authenticator软件,上面有下载地址.根据自己的手机系统选择.

安装完成之后我们打开Google Authenticator

如下图:点击+号



wKiom1OEGSyx8bhpAACqKQiM4n4476.png

第二部填写KEY 用户名 Account:这里可以随意填写  下面的KEY就是刚才生成的那个 填写完成之后点击Done完成

wKioL1OEGQDimX1uAAJc9jxDBA0715.png

224400就是我们的验证码,跟刚才生成确认是一致的.

wKiom1OEGS2zpYzyAAHNfATpxhE787.png

完成之后,就每30S生成一次动态密码 如下,用下面这个动态密码我们就可以登录SSH了,如果要编辑也可以点击EDIT进行编辑或者删除.

wKioL1OEGQGgx5d0AAD9sAoBokM261.png

如下图我们输入动态密码后 在输入密码就可以进入系统了

wKiom1OEGgXx7MMTAAEi9hRFdSc736.jpg


客户端也可以在浏览器上生成 以火狐为例 

在以下地址安装gauth-authenticato插件

https://marketplace.firefox.com/app/gauth-authenticator/

安装完毕打开插件 如图:

点击+号添加

wKiom1OEHqaCHQ0HAAGEIokxpVA575.jpg

和手机一样填写用户名和KEY KEY和生成的一样 用户名随意填写

wKioL1OEHnqivsGuAAHhtkcT9Ds901.jpg

完成之后生成的验证码如下:

wKiom1OEHqfC91MGAAHJY9b1YXs539.jpg


参考:http://www.361way.com/google-authenticator-ssh/2186.html

参考:http://blog.itpub.net/7607759/viewspace-1161112





      本文转自flyingzf  51CTO博客,原文链接:http://blog.51cto.com/flyingzf/1417568,如需转载请自行联系原作者






相关文章
|
Linux 网络安全 数据安全/隐私保护
linux 本地终端 SSH 连接 gcp (Google Cloud Platform ) 配置教程
linux 本地终端 SSH 连接 gcp (Google Cloud Platform ) 配置教程
10220 0
|
算法 安全 Shell
SSH:加密安全访问网络的革命性协议
SSH:加密安全访问网络的革命性协议
815 9
|
安全 Linux 网络安全
|
网络安全 开发工具 数据安全/隐私保护
使用ssh RSA加密方式授权git
使用ssh RSA加密方式授权git
448 0
使用ssh RSA加密方式授权git
|
算法 Linux 网络安全
CentOS7下利用Google Authenticator实现SSH登录的二次身份验证
CentOS7下利用Google Authenticator实现SSH登录的二次身份验证
1980 0
CentOS7下利用Google Authenticator实现SSH登录的二次身份验证
|
Java 网络安全 数据安全/隐私保护
Java实现SSH模式加密(2)
Java实现SSH模式加密
382 0
|
安全 Java 网络安全
Java实现SSH模式加密(1)
Java实现SSH模式加密
402 0
|
Linux 网络安全 Docker
盘古栈云,创建带ssh服务的linux容器
创建带ssh服务的linux容器
547 146
|
安全 Linux Shell
Linux中SSH命令介绍
Linux中SSH命令介绍
1009 2
|
监控 Linux 网络安全
FinalShell SSH工具下载,服务器管理,远程桌面加速软件,支持Windows,macOS,Linux
FinalShell是一款国人开发的多平台SSH客户端工具,支持Windows、Mac OS X和Linux系统。它提供一体化服务器管理功能,支持shell和sftp同屏显示,命令自动提示,操作便捷。软件还具备加速功能,提升访问服务器速度,适合普通用户和专业人士使用。
4119 0

热门文章

最新文章