Linux下部署SSH登录时的二次身份验证环境记录(利用Google Authenticator)
一般来说,使用ssh远程登录服务器,只需要输入账号和密码,显然这种方式不是很安全。为了安全着想,可以使用GoogleAuthenticator(谷歌身份验证器),以便在账号和密码之间再增加一个验证码,只有输入正确的验证码之后,再输入密码才能登录。这样就增强了ssh登录的安全性。账号、验证码、密码三者缺一个都不能登录,即使账号和密码正确,验证码错误,同样登录失败。其中,验证码是动态验证码,并且是通过手机客户端自动获取(默认每隔30秒失效一次)。好了,废话不多说了,下面记录下GoogleAuthenticator部署过程(Centos6系统下):
一、关闭SELINUX
[root@test ~]# vim /etc/selinux/config #永久关闭。需要reboot重启后生效
SELINUX=disabled [root@test ~]# setenforce 0 #临时性关闭。不需要reboot重启
二、安装编辑工具包
[root@test ~]# yum install wget gcc make
[root@test ~]# yum install pam-devel libpng-devel 下载repoforge第三方yum源及libpam-google-authenticator-1.0-source.tar.bz2、qrencode-3.4.4.tar.gz(后两个软件需要在翻墙条件下才能下载。这里我提前下载了)
下载地址:https://pan.baidu.com/s/1i4WDbyX
提取密码:anxd 下载到/data/software目录下
[root@test ~]# cd /data/software/
[root@test software]# ls
libpam-google-authenticator-1.0-source.tar.bz2 qrencode-3.4.4.tar.gz rpmforge-release-0.5.3-1.el6.rf.x86_64.rpm [root@test software]# rpm -ivh rpmforge-release-0.5.3-1.el6.rf.x86_64.rpm [root@test software]# yum install mercurial 安装google authenticator PAM插件
[root@test ~]# cd /data/software/
[root@test software]# tar -jxvf libpam-google-authenticator-1.0-source.tar.bz2
[root@test software]# cd libpam-google-authenticator-1.0
[root@test libpam-google-authenticator-1.0]# make && make install 安装QrenCode,此工具可以在Linux命令行下生成二维码
[root@test ~]# cd /data/software/
[root@test software]# tar -zvxf qrencode-3.4.4.tar.gz
[root@test software]# cd qrencode-3.4.4
[root@test qrencode-3.4.4]# ./configure --prefix=/usr
[root@test qrencode-3.4.4]# make && make install
三、配置ssh服务调用google authenticator PAM插件
[root@test ~]# vim /etc/pam.d/sshd #在第一行(即auth required pam_sepermit.so的下一行)增加以下代码
auth required pam_google_authenticator.so [root@test ~]# vim /etc/ssh/sshd_config
......
ChallengeResponseAuthentication yes #修改no为yes [root@test ~]# service sshd restart
四、使用google authenticator PAM插件为ssh登录账号生成动态验证码
注意:哪个账号需要动态验证码,请切换到该账号下操作。(可以在不同用户下执行这个命令以生成各自的二次验证码)
[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@BJLX_NET_TEST-01%3Fsecret%3DCGB5NWP6SABN3TM7 #这个链接只能在翻墙条件下才能打开

Your new secret key is: CGB5NWP6SABN3TM7 #如果在手机的谷歌身份验证器上不想通过"扫描条形码"的方式添加,就输入这个key,通过"手动输入验证码的方式"。账号就是服务器主机名。
Your verification code is 730249
Your emergency scratch codes are: #下面会生成5个紧急验证码(当无法获取动态验证码或验证码不能使用使用可以使用这5个)
66151894 #需要注意的是:这5个验证码用一个就会少一个!请保存好!
91475582
37383236
70667696
70522112
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 #禁止使用相同口令
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 #默认动态验证码在30秒内有效,由于客户端和服务器可能会存在时间差,可将时间增加到最长4分钟,是否要这么做:这里选择是n,继续默认30秒
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 #是否限制尝试次数,每30秒只能尝试最多3次,这里选择y进行限制
五、手机安装Google身份验证器,通过此工具扫描上一步生成的二维码图形,获取动态验证码。
在App Store里直接可以下载Authenticator



然后扫描上面在服务器上生成的二维码,每个用户都会有一个单独的二维码

接着在ssh的客户端里设置,如下,设置"Keyboard Interactive"方式登录

然后再次连接的时候,就会提示先输入二次身份验证码,再输入用户密码。



在linux客户机上远程登录,效果一样:
[wangshibo@BJLX_NET_TEST-01 ~]$ ssh root@172.29.32.251
The authenticity of host '[172.29.32.251]:22 ([172.29.32.251]:22)' can't be established.
RSA key fingerprint is 5c:e7:1a:05:8b:2e:66:99:20:90:1f:47:56:bf:b9:41.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '[172.29.32.251]:22' (RSA) to the list of known hosts.
Verification:
Password:
[root@test ~]#
Linux下部署SSH登录时的二次身份验证环境记录(利用Google Authenticator)的更多相关文章
- Linux 下使用 ssh 登录局域网其他电脑的方法
Linux 下使用 ssh 登录局域网其他电脑的方法 首先查看电脑是否安装 ssh 客户端,如果没有执行下面命令安装客户端. sudo apt-get install openssh-client s ...
- linux下更改ssh登录前的banner信息
默认情况下,telnet ip 22端口会显示 openssh的版本信息 whereis sshd 如 cp /usr/sbin/sshd /usr/sbin/sshd2016.bak sed -i ...
- LINUX下的ssh登录之后的文件远程copy:scp命令(接前文ssh登录)
先记录参考: 1:http://www.cnblogs.com/peida/archive/2013/03/15/2960802.html 2:http://www.vpser.net/manage/ ...
- linux下MySQL安装登录及操作
linux下MySQL安装登录及操作 二.安装Mysql 1.下载MySQL的安装文件 安装MySQL需要下面两个文件: MySQL-server-4.0.16-0.i386.rpm MySQL-cl ...
- Linux 下部署Django项目
Linux 下部署Django项目 说明:本文所使用的环境为CentOS 6+Python2.7+Django1.11 安装Django.Nginx和uWSGI 1.确定已经安装了2.7版本的Py ...
- linux下开启SSH,并且允许root用户远程登录,允许无密码登录
参考:http://blog.csdn.net/jia0511/article/details/8237698 1. 允许root用户远程登录 修改ssh服务配置文件 sudo vi /etc/ssh ...
- ssh-keygen+ssh-copy-id 在linux下实现ssh无密码登录访问(转)
转自:http://blog.csdn.net/pennyliang/article/details/8556662 ssh-keygen+ssh-copy-id 在linux下实现ssh无密码登录访 ...
- 【转】linux下设置ssh无密码登录
ssh配置 主机A:10.0.5.199 主机B:10.0.5.198 需要配置主机A无密码登录主机A,主机B 先确保所有主机的防火墙处于关闭状态. 在主机A上执行如下: 1. $cd ~/.ssh ...
- linux下设置SSH无密码登录
ssh配置 主机A:10.0.5.199 主机B:10.0.5.198 需要配置主机A无密码登录主机A,主机B 先确保所有主机的防火墙处于关闭状态. 在主机A上执行如下: 1. $cd ~/.ssh ...
随机推荐
- [MapReduce_add_2] MapReduce 实现年度最高气温统计
0. 说明 编写 MapReduce 程序实现年度最高气温统计 1. 气温数据分析 气温数据样例如下: ++023450FM-+000599999V0202701N015919999999N00000 ...
- VMware虚拟机中CentOS 7的硬盘空间扩容
查看centos7系统挂载点信息 扩展VMWare-centos7硬盘空间 对新增加的硬盘进行分区.格式化 添加新LVM到已有的LVM组,实现扩容 1.查看centos7系统挂载点信息 df -h查看 ...
- python——虚拟环境之virtualenv(windows10,64位)
1 问题 当我们拥有两个甚至多个项目A.B.C......,各个项目正常运行需求的python运行环境都不相同.而默认情况下,不管哪个项目,使用的都是全局的Python环境.上述情况,造成的问题就是, ...
- [项目实践] python文件路径引用的规则,记一次使用sys.path[0]的问题,及如何区分 ../与 ./的使用场景
下面是一个获取配置的代码 def getValue(self,section,option): """ @file: string,the name of the con ...
- 【错误记录】PowerShell 超级无语的语法错误(令人怀疑人生)
曾经做过测试,本文是本章优秀测试人员的精神,必须定位到原因,不然吃不下饭.其实可以很容易绕过这种问题. 环境: PowerShell 5.1.16299.64 Windows 10 现有代码如下: # ...
- Matplotlib常用绘图示例
一.Matplotlib介绍 Matplotlib是一个Python的2D绘图库,它以各种硬拷贝格式和跨平台的交互式环境生成出版质量级别的图形.通过Matplotlib,开发者可以仅需要几行代码,便可 ...
- Robberies HDU - 2955
直接说题意吧.(什么网友bb了半天题都说不清楚) 给了 P 表示大于这个概率一定被抓住.则P表示被抓住的概率.N表示现在有的银行,pi表示被抓的概率嘛. 然后,就看数学了.肯定不能算被抓的概率啊. ...
- MATLAB中floor、round、ceil、fix区别
Matlab取整函数有: fix, floor, ceil, round.具体应用方法如下:fix朝零方向取整,如fix(-1.3)=-1; fix(1.3)=1;floor,顾名思义,就是地板,所以 ...
- 深入浅出的webpack构建工具---webpack3版本的CommonsChunkPlugin详解(六)
阅读目录 一:什么是CommonsChunkPlugin, 它的作用是什么? 二:webpack3中CommonsChunkPlugin配置项及含义? 回到顶部 一:什么是CommonsChunkPl ...
- eureka client服务续约源码分析
必备知识: 1.定时任务 ScheduledExecutorService public class demo { public static void main(String[] args){ Sc ...