ssh动态验证码登录机器

Google Authenticator是一个动态验证码程序,兼容各种智能手机平板设备,可以用来做各种帐号的二次验证,增加帐号的安全性。SSH是Linux系统的最重要防线之一,为了防止密码泄露或者被爆破,可以使用Google Authenticator来做二次验证,使用方法也很简单

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

操作系统环境

[root@iZ25nmodinrZ ~]# cat /etc/issue
\S
Kernel \r on an \m

操作步骤如下

1.关闭selinux

[root@iZ25nmodinrZ ~]# sed -i 's@SELINUX=enforcing@SELINUX=disabled@' /etc/selinux/config

注:需要重启生效

[root@iZ25nmodinrZ ~]# setenforce 0

注:临时关闭生效提示警告不影响使用


查看selinux是否关闭

[root@iZ25nmodinrZ ~]# getenforce
Disabled

2.安装软件依赖组件

[root@iZ25nmodinrZ ~]# yum -y install gcc make pam-devel libpng-devel libtool wget git

3.添加阿里云epel源

[root@iZ25nmodinrZ ~]# wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo

4.qrencode安装,谷歌身份验证器要调用那程序生成并显示二维码

[root@iZ25nmodinrZ ~]# yum -y install qrencode

5.安装谷歌身份验证器

[root@iZ25nmodinrZ ~]# mkdir -p /app
[root@iZ25nmodinrZ ~]# cd /app
[root@iZ25nmodinrZ app]# git clone https://github.com/google/google-authenticator.git
Cloning into 'google-authenticator'...
remote: Counting objects: 1461, done.
remote: Total 1461 (delta 0), reused 0 (delta 0), pack-reused 1460
Receiving objects: 100% (1461/1461), 2.33 MiB | 25.00 KiB/s, done.
Resolving deltas: 100% (776/776), done.
[root@iZ25nmodinrZ app]# cd google-authenticator/libpam/
[root@iZ25nmodinrZ libpam]# ./bootstrap.sh
[root@iZ25nmodinrZ libpam]# ./configure
[root@iZ25nmodinrZ libpam]# make
[root@iZ25nmodinrZ libpam]# make install
[root@iZ25nmodinrZ libpam]# cp .libs/pam_google_authenticator.so /lib64/security/

6.配置PAM,添加谷歌身份验证器PAM模块配置

[root@iZ25nmodinrZ ~]# head -n 2 /etc/pam.d/sshd
#%PAM-1.0
auth       required    pam_google_authenticator.so

7.修改ssh服务配置文件sshd_config

[root@iZ25nmodinrZ libpam]# sed -i 's#^ChallengeResponseAuthentication no#ChallengeResponseAuthentication yes#' /etc/ssh/sshd_config

8.重启ssh服务

[root@iZ25nmodinrZ libpam]# systemctl restart sshd.service

9.生成二次验证码的系统账号后运行验证器程序google-authenticator,或者切换到相应用户需要需要进行二次验证码的用户,这里我是直接使用root用户验证

[root@iZ25nmodinrZ ~]# google-authenticator Do you want authentication tokens to be time-based (y/n) y #提示是否要基于时间生成令牌,选择y
https://www.google.com/chart?chs=200x200&chld=M|0&cht=qr&chl=otpauth://totp/root@iZ25nmodinrZ%3Fsecret%3D44FOMDL4D5NC7RFJD4CJDDGXFM%26issuer%3DiZ25nmodinrZ

Your new secret key is: 44FOMDL4D5NC7RFJD4CJDDGXFM
Your verification code is 770892
Your emergency scratch codes are:2302871312647530287154208254067313054818
#上面的网址为生成的二维码图形地址(需要×××才能打开),还会生成密钥,以及5个紧急验证码(当无法获取动态验证码时使用,注意:这5个验证码用一个就会少一个!请保存好!)
Do you want me to update your "/root/.google_authenticator" file? (y/n) y  #提示是否要更新验证文件,选择yDo 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  #默认动态验证码在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进行限制

10.手机安装谷歌身份验证器,苹果手机打开app store搜索应用Google Authenticator,安卓系统打开相应的应用进行安装即可,由于我使用的是安卓系统安装的是安卓版的

11.打开APP后点击“开始设置”,扫描终端的二维码,需要安装专用的条码扫描器,其他软件都无法扫描二维码无效,由于我的手机无法番墙,所以只能使用秘钥的方式了

配置好后的身份验证器 

12.由于终端使用的是crt,需要进行设置

使用SecureCRT客户端的话,默认情况下会不支持这种验证方式,只要在会话选项中修改SSH—-Authentication,设置为Keyboard Interactive即可,其他的选项包括Password都要去掉

13.使用crt登录

 
注:使用Publickey免密码登录方式来登录ssh的话,不支持使用Google Authenticator验证,必须是密码验证的登录方式才支持。

转载于:https://blog.51cto.com/noodle/1831697

Linux下使用ssh动态验证码登陆机器相关推荐

  1. Linux下使用SSH、Crontab、Rsync三工具实现数据自动备份

    Linux下使用SSH.Crontab.Rsync三工具实现数据自动备份 作为网管人员大概都无一例外的经历过系统备份,尤其是重要系统的备份.重要数据库系统的备份工作.由于备份是个频繁而琐碎的工作,如何 ...

  2. linux动态库路径生效,Linux下如何解决动态库的链接问题

    原标题:Linux下如何解决动态库的链接问题 静态库是一种以空间换取时间和移植性的做法,一些情况下确实有着一定的意义,但是一些情况下,我们自己编写的简单项目,在绝大多数的机器上不存在移植性问题,是没有 ...

  3. linux互信,Linux 下实现SSH互信

    Linux 下实现SSH互信 一.准备两台服务器: A机:192.168.1.1 B机:192.168.1.2 二.双机建立信任 1.在A机生成秘钥证书 在root下执行ssh-keygen命令,一路 ...

  4. ssh远程执行命令 linux,Linux下使用SSH远程执行命令方法收集

    说明:可以做SSH免密登录之后执行,这样可以省去每次执行输入密码的提示. 对于简单的命令: 如果是简单执行几个命令,则: ssh user@remoteNode "cd /home ; ls ...

  5. Linux下修改SSH登录端口

    Linux下修改SSH登录端口 LINUX 的默认SSH 端口是 22.为了防止别人暴力破解,建议修改SSH 访问端口:vim /etc/ssh/sshd_config 找到Port 22 这一行,这 ...

  6. linux下tomcat发布网站验证码获取不到

    linux下tomcat发布网站验证码获取不到 本地打好WAR包发布到tomcat后启动服务,在外网浏览网站,能正常访问,但是登录时候发现验证码图片发不出,导致系统无法正常登录. 解决办法:进入tom ...

  7. Linux使用SSH上传下载文件,Linux下通过ssh scp命令上传下载文件

    Linux下通过ssh scp命令上传下载文件. 1.上传本地文件到服务器 scp /path/filename username@servername:/path/ 例如 scp /var/tale ...

  8. linux下一些操作技巧-root登陆;安装SSH;安装samba等等

    我使用linux,主要是编写驱动,测试程序,这里记录一些常用的操作方法,注意有一些操作会带来安全问题,所以请勿在主要工作机器上尝试. ubuntu添加root登陆方式 sudo passwd root ...

  9. 查看linux下程序或者动态库到底依赖哪些so动态库以及对应的版本

    一. ldd命令 基本上每一个linux 程序都至少会有一个动态库,查看某个程序使用了那些动态库,使用ldd命令查看 # ldd /bin/ls linux-vdso.so.1 => (0x00 ...

最新文章

  1. Facebook打算与Google的人工智能一较高下吗?
  2. MBR区、DBR区、FAT区、DIR区和DATA区的区别
  3. Worktile 技术架构概要
  4. 深入浅出Mybatis系列(四)---配置详解之typeAliases别名(mybatis源码篇)
  5. 我应该使用32位还是64位JVM?
  6. 树形结构 —— 树与二叉树 —— 树的数据生成器
  7. 换服务器要重新百度站长验证站点吗6,六个步骤搞定更换网站服务器
  8. Linux内存管理 -- /proc/{pid}/smaps讲解
  9. 工行软开和中行软开_工行软开怎么样啊待遇如何,知道的说下啊
  10. excel 比对字符
  11. ajax blockUI
  12. 使用IDEA搭建SSM项目
  13. 二元置信椭圆r语言_医学统计与R语言:Meta 回归作图(Meta regression Plot)
  14. 信息系统集成有以下几个显著特点
  15. matlab求解常微分方程的实验,实验五__用matlab求解常微分方程
  16. 个人账号转企业账号及邓白氏编码申请经验分享
  17. 一文精通S4 HANA中的Business Partner
  18. 单点登录-CAS介绍
  19. UTL_FILE详解
  20. 读取Excel表格内容转为Sql when then语句

热门文章

  1. 多传感器融合之滤波(二)EKF
  2. 利用负载均衡优化和加速HTTP应用
  3. DataGrid删除确认及Item颜色交替
  4. 只要可能,就缓存数据和页输出
  5. 如何定制一款12306抢票浏览器——启动“人”线程
  6. Ubuntu14.04下配置OpenGL及测试代码
  7. 【MySQL】缩略语PK NN UQ BIN UN ZF AI G、基本操作语句
  8. Travis CI : 最小的分布式系统(一)
  9. Makefile的东西
  10. #Ruby# Introspect (2)