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

1.安装依赖包,环境属于centos7,centos6请自行查阅网上资料

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

2.安装Google Authenticator PAM插件安装

[root@bgx ~]# wget https://github.com/google/google-authenticator-libpam/archive/1.04.tar.gz
[root@bgx ~]# tar xf 1.04.tar.gz
[root@bgx ~]# cd google-authenticator-libpam-1.04/
[root@bgx google-authenticator-libpam-1.04]# ./bootstrap.sh
[root@bgx google-authenticator-libpam-1.04]# ./configure
[root@bgx google-authenticator-libpam-1.04]# make && make install
[root@bgx google-authenticator-libpam-1.04]# cp /usr/local/lib/security/pam_google_authenticator.so /lib64/security/

3.初始配置 Google Authenticator

[root@bgx google-authenticator-libpam-1.04]# google-authenticator

是否基于时间的认证,为了防止不同跨时区的问题,这里选择n

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

然后会跳出一个google的二维码
红色框框是: 生成的密钥
绿色框框是: 生成的5个一次性紧急验证码,用于紧急情况下,使用过一次后该验证码即失效了。

是否更新用户的 Google Authenticator 配置文件,选择 y 才能使上面操作对当前 root
用户生效,其实就是在对应用户的 Home 目录下生成了一个 .google_authenticator 文件,如果你想停用这个用户的
Google Authenticator 验证,只需要删除这个用户 Home 目录下的 .google_authenticator
文件就可以了。

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

每次生成的令牌30s生成一次,最高允许存在误差4分钟。

By default, a new token is generated every 30 seconds by the mobile app.
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. This allows for a
time skew of up to 30 seconds between authentication server and client. If you
experience problems with poor time synchronization, you can increase the window
from its default size of 3 permitted codes (one previous code, the current
code, the next code) to 17 permitted codes (the 8 previous codes, the current
code, and the 8 next codes). This will permit for a time skew of up to 4 minutes
between client and server.
Do you want to do so? (y/n) y

4.SSH调用及客户端配置,添加pam认证,在第一行添加

[root@bgx ~]# vim  /etc/pam.d/sshd  #添加如下行
auth required pam_google_authenticator.so

5.修改sshd配置,关联google认证

[root@bgx ~]# vim /etc/ssh/sshd_config
ChallengeResponseAuthentication yes #修改为yes
[root@bgx ~]# systemctl restart sshd #重启sshd服务

6.客户端通过ssh连接服务器测试

需要输入动态密码,动态密码通过手机获取如下图所示

7.查看服务端的安全日志文件,可以看到是先进程google动态密码认证

8.注意事项:
1.用password + google authenticator,如果使用公钥登录的话,会跳过google authenticator验证直接登录服务器的。
2.如果是内网测试使用,建议安装google authenticator 浏览器插件实践。如果是公网服务器建议安装手机版的Authenticator

9.安装Google authenticator
Andorid版: “自行百度”
iOS版: 下载 “Authenticator”
chrome浏览器有google authenticator的插件

ssh密码登录+ Google Authenticator 实现双向认证的更多相关文章

  1. 关闭ssh密码登录

    我们经常使用SSH登录管理服务器,在享受便利的同时也会遇到一些安全隐患,最常见的就是SSH密码被暴力破解.如果我们将SSH密码设置的过于复杂,又不容易记,因此限制SSH登录方式,只能使用key登录是一 ...

  2. Linux免SSH密码登录

    SSH免密码登录,做个总结吧! 1.安装SSH服务(略过) 2.场景:需要配置主机A无密码登录主机B 在主机A上执行如下: cd ~/.ssh ssh-keygen -t rsa 生成密钥文件 cp ...

  3. 配置SSH密码登录

    在客户端生成公钥: ssh-keygen –t rsa 生成的公钥默认位置在~/.ssh/目录 把公钥上传到服务器端: scp id_rsa.pub root@ip地址:文件保存路径 cat id_r ...

  4. python批量操作Linux服务器脚本,ssh密码登录(执行命令、上传、下载)(一)

     -*-          paramiko.util.log_to_file(         ssh = paramiko.SSHClient()          ssh.set_missing ...

  5. ssh密码登录

    https://stackoverflow.com/a/16928662/8025086 https://askubuntu.com/a/634789/861079 #!/usr/bin/expect ...

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

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

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

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

  8. Linux下使用Google Authenticator配置SSH登录动态验证码

    1.一般ssh登录服务器,只需要输入账号和密码.2.本教程的目的:在账号和密码之间再增加一个验证码,只有输入正确的验证码之后,再输入密码才能登录.这样就增强了ssh登录的安全性.3.账号.验证码.密码 ...

  9. 为效率而生:开源Mac版Google Authenticator认证客户端GoldenPassport

    最近运维同学为了提高安全性,用Google Authenticator对服务器加了双重认证,此后登录服务器需要先输入动态密码,在输入服务器密码.Google Authenticator相当于软toke ...

随机推荐

  1. Laravel是怎样防止你的定时任务重复执行的

    基本介绍 有时候一个定时任务执行需要的时间可能会比我们想象的要长,这就会引起一个问题——当前任务还没有执行完毕的时候另一个相同的任务也会执行,从而导致任务重复.例如想象一下我们执行每分钟生成一次报告的 ...

  2. 最新的JavaScript核心语言标准——ES6,彻底改变你编写JS代码的方式!

    原文地址 迁移到:http://www.bdata-cap.com/newsinfo/1741515.html 本文内容 ECMAScript 发生了什么变化? 新标准 版本号6 兑现承诺 迭代器和f ...

  3. redis的两种持久化方案

    前言 人生在于折腾系列,网络,多线程等系列博客楼主还在继续折腾也不会放弃.缓存的知识其实并不仅仅在于简单的增删改查,我觉得有必要全面深入的学习一波.记录学习的过程与体悟. RDB 什么是RDB 对re ...

  4. Eureka2.0集群环境

    当有2个eureka注册中心构建eureka注册中心集群时,1:微服务的注册中心地址要写2个eureka注册中心的地址,以逗号分隔2:其中1个eureka注册中心A保留有微服务的注册信息,作为主注册中 ...

  5. html书写行内元素时-tab和换行会在行内元素间引入间距

    目录 html文本中的控制字符会被解析为文本节点 书写行内元素时,换行符LF与水平制表符HT会引入莫名的元素间间隔 其他控制字符是否会引入间距的验证 html文本中的控制字符会被解析为文本节点 举例: ...

  6. uni-app常用 HTML5+APP 设置

    1.锁定屏幕方向 锁定屏幕方向后屏幕只能按锁定的屏幕方向显示,关闭当前页面后仍然有效. 可再次调用此方法修改屏幕锁定方向或调用 unlockOrientation() 方法恢复到应用的默认值. 锁定屏 ...

  7. cc.isChildClassOf 判断两个类的继承关系

    使用 cc.isChildClassOf 来判断两个类的继承关系: var Texture = cc.Class(); var Texture2D = cc.Class({ extends: Text ...

  8. Android源码分析(十五)----GPS冷启动实现原理分析

    一:原理分析 主要sendExtraCommand方法中传递两个参数, 根据如下源码可以知道第一个参数传递delete_aiding_data,第二个参数传递null即可. @Override pub ...

  9. angular6 使用daterangepicker的注意事项

    具体使用方法可参考这篇博客:https://blog.csdn.net/qq_43225030/article/details/84973086 需要注意的地方是,在dateRangePicker函数 ...

  10. <人人都懂设计模式>-中介模式

    真正的用房屋中介来作例子, 好的书籍总是让人记忆深刻. class HouseInfo: def __init__(self, area, price, has_window, has_bathroo ...