公司线上的使用机器不能让用户随意的登陆,所以就不能让开发随意的登陆到生产的机器的。于是就打算使用google-auth的验证方式呢。

  如果google-auth的方式。

 搭建google-authenticator:

  搭建这个很简单,如下:

  git clone https://github.com/google/google-authenticator-libpam 下载最新的google auth 最新版。

  cd google-authenticator-libpam/

  ./bootstrap.sh

  ./configure && make && make install

  ln -s /usr/local/lib/security/pam_google_authenticator.so /lib64/security/pam_google_authenticator.so

  修改/etc/pam.d/sshd,

  #最上方加一行 "auth required pam_google_authenticator.so"
   #这个配置可以更复杂一些,加上一些参数,详见 libpam/README
   #注:如果遇到仍然需要输入密码的情况,改成 "auth sufficient pam_google_authenticator.so" 试试。

  修改/etc/ssh/sshd_config

  将 ChallengeResponseAuthentication 选项的 no 改成 yes

  将 UsePAM yes

  service sshd restart

  生成密钥

  $ google-authenticator    #注:运行这个命令的是需要登录的用户,不是root用户
  Do you want authentication tokens to be time-based (y/n) y  (确认:基于时间的认证token)
  【这里会显示生成二维码的地址、二维码、密钥明文、应急码】
  Do you want me to update your "/var/www/.google_authenticator" file (y/n) y (确认:更新配置文件)
  ......
  size of 1:30min to about 4min. Do you want to do so (y/n) n (token有效期是1.5min,选y就是4min)
  ......
  Do you want to enable rate-limiting (y/n) y (30s内只允许尝试三次)

  在app里扫二维码,或者手动输入密钥,即可看到token每隔30s更新一次了

  尝试登录
  $ ssh localhost
  verification code: 【输入验证码】
  password: 【输入密码】

补:

但当时只是简单加上了Google Authenticator,实际使用中既要输入验证又要输入密码,太繁琐了,所以在搭建我司跳板机的时候,选择了用 publickey + authenticator 的方案,只需要输入一次验证码即可。但是这里要求很多。如openssh的版本大于6.2,如果不是的话,就无法使用AuthenticationMethods,最好的方式是使用centos7的版本(已验证过可以使用)centos6.5测试无法使用(应该是我技术不行)。

具体的配置方案变化不大,主要是用上了 SSH 6.2+ 新增的 AuthenticationMethods 参数,可以指定一系列验证方法,具体配置如下:

引用
#默认需要先用publickey验证,再用验证码
AuthenticationMethods publickey,keyboard-interactive

#对于指定的IP,只需要publickey验证
Match Address 10.0.0.4
    AuthenticationMethods publickey

#也可以指定用户只需要publickey验证
#Match User XXX
    #AuthenticationMethods publickey

顺便吐槽一下,Linux这套东西折腾起来真是要命,今天配置跳板机备份机的时候,完全相同的配置,复制一份就是不对,虽然配置里只指定了publickey,keyboard-interactive,但是每次输完验证码以后还是要求输入密码才行,折腾了几个小时才发现,不知道从什么时候开始,"auth required pam_google_authenticator.so" 已经不合适了,需要改成 "auth sufficient pam_google_authenticator.so",这样才会在输入验证码以后就结束认证过程(sufficient的实现里加了一个break?什么鬼。)(感谢 @ https://serverfault.com/a/740881/343388

最后,提醒一下使用SecureCRT的同学,你需要在Session Options -> Connection -> SSH2,将Authentication中只选用 "Keyboard Interactive" ,否则没法正常登录。

-------------------------

如果你喜欢这篇文章,可以用支付宝或微信扫码赞赏让我知道

-->

  错误:configure: error: Unable to find the PAM library or the PAM header files

  方法:yum install -y pam-devel

  

引用:https://www.felix021.com/blog/read.php?2133

   https://www.felix021.com/blog/read.php?2172 

堡垒机安装google-authenticator的更多相关文章

  1. jumpserver堡垒机安装

    1. 下载jumpserver cd /opt wget https://github.com/jumpserver/jumpserver/archive/master.zip unzip maste ...

  2. JumpServer堡垒机安装笔记

    厂商文档--一步一步安装CentOS(https://jumpserver.readthedocs.io/zh/master/setup_by_centos.html) 厂商文档--简单优化(http ...

  3. Google Authenticator

    Google Authenticator 现在越来越多的网站采用两步验证,实现方式可能有所区别,一般来说是 1+? (1 即 普通的用户名和密码, ?可能是实物如U盾.手机短信验证码或其他).?的重点 ...

  4. SSH + Google Authenticator 安全加固

    1. SSH连接 Secure Shell(安全外壳协议,简称SSH)是一种加密的网络传输协议,可在不安全的网络中为网络服务提供安全的传输环境.SSH通过在网络中创建安全隧道来实现SSH客户端与服务器 ...

  5. 【Linux】使用Google Authenticator 实现ssh登录双因素认证

    一般来说,使用ssh远程登录服务器,只需要输入账号和密码,显然这种方式不是很安全.为了安全着想,可以使用GoogleAuthenticator(谷歌身份验证器),以便在账号和密码之间再增加一个验证码, ...

  6. Linux下部署SSH登录时的二次身份验证环境记录(利用Google Authenticator)

    一般来说,使用ssh远程登录服务器,只需要输入账号和密码,显然这种方式不是很安全.为了安全着想,可以使用GoogleAuthenticator(谷歌身份验证器),以便在账号和密码之间再增加一个验证码, ...

  7. Google Authenticator(谷歌身份验证器)

    <!DOCTYPE html>Google Authenticator(谷歌身份验证器) ] Google Authenticator(谷歌身份验证器) Google Authentica ...

  8. ssh密码登录+ Google Authenticator 实现双向认证

    通常我们直接通过ssh输入密码连接服务器,但这样很容易出现暴力破解情况,所以我们可以结合google的动态认证+ssh密码,这样能够大大的提升登陆的安全. 简单来说,就是当用户通过ssh登陆系统时,先 ...

  9. 计算机网络安全 —— C# 使用谷歌身份验证器(Google Authenticator)(五)

    一.Google Authenticator 基本概念  Google Authenticator是谷歌推出的一款动态口令工具,旨在解决大家Google账户遭到恶意攻击的问题,在手机端生成动态口令后, ...

随机推荐

  1. C语言知识点记录

    1,栈底指针不变,栈顶指针变化. 2,结构化程序包括:顺序,分支,循环. 3,详细设计的任务是为软件结构图的每一个模块确定实现算法和局部数据结构. 4,数据操纵语言:负责数据的操纵,包括查询及增,删, ...

  2. Json日期格式化,出去返回的T

    第一种办法:前端JS转换: //格式化显示json日期格式 function showDate(jsonDate) { var date = new Date(jsonDate); var forma ...

  3. WechatPro_页面创建

    1. 全局三个文件,app.js, app.json, app.wxss(名称不可更改) 2.创建Pages目录文件,用来放置各个页面 3.创建页面(页面命名,创建四个文件) (1)js:页面逻辑实现 ...

  4. systomctl与service的区别主要是版本区别

    redhat和centos在7及以后的版本,用systemctl命令 redhat和centos在6及6以前的版本,用service命令. 两者的区别,如下. 举例 这里的.service可以不写,如 ...

  5. 解决Vue 使用vue-router切换页面时 页面显示没有在顶部的问题

    有时候我们需要页面滚动条滚动到某一固定的位置,一般使用Window scrollTo() 方法. 语法就是:scrollTo(xpos,ypos) xpos:必需.要在窗口文档显示区左上角显示的文档的 ...

  6. java模板字符串功能的简单实现

    package com.Interface.util; import lombok.extern.slf4j.Slf4j; /** * 测试类 * * @author 华文 * @date 2019年 ...

  7. k sum 问题系列

    转自:http://tech-wonderland.net/blog/summary-of-ksum-problems.html (中文旧版)前言: 做过leetcode的人都知道, 里面有2sum, ...

  8. 软件版本 Alpha、Beta、Rc

    软件版本的周期 α.β.γ 表示软件测试中的三个阶段 α :第一阶段,内部测试使用 β: 第二阶段,消除了大部分不完善的地方,仍可能存在漏洞,一般提供给特定的用户使用 γ: 第三阶段,产品成熟,个别地 ...

  9. Codeforces Round #600 (Div. 2) - B. Silly Mistake(模拟)

    题意:有一个公司,每天有员工进出,$a[i]>0$时表示$a[i]$这个员工进入公司,$a[i]<0$时表示$-a[i]$这个员工出公司,公司对进出办公室有一些严格的规定 员工每天最多只能 ...

  10. Mysql安装 ----> 基于源码包安装

    1)基于源码包安装MySQL [root@localhost ~]# rpm -q mysql mysql-server mariadb mairadb-server           //检查有没 ...