SSH使用Google Authenticator二次验证


基本的原理如上图:

客户端在输入code码之后,才可以输入服务器的密码,进行账户验证,方可进入服务器。

实现方式如下:

1. 安装所需组件

# yum -y install mercurial pam-devel

2.  安装qrencode,在Linux上,有一个名为 QrenCode 的命令行工具可以很容易帮我们生成二维码,google authenticator命令行生成二维码就是调用它。

# wgethttp://fukuchi.org/works/qrencode/qrencode-3.3.1.tar.gz

# tar zxfqrencode-3.3.1.tar.gz

# cdqrencode-3.3.1

# ./configure--prefix=/usr && make && make install

3. 安装GoogleAuthenticator

# wget --no-check-certificate https://google-authenticator.googlecode.com/files/libpam-google-authenticator-1.0-source.tar.bz2

# tar jxvf libpam-google-authenticator-1.0-source.tar.bz2
# cd libpam-google-authenticator-1.0
# make && make install

4. SSH登录时调用google-authenticator模块

vim /etc/pam.d/sshd
在第一行添加如下:

auth       required    pam_google_authenticator.so

vim /etc/ssh/sshd_config

ChallengeResponseAuthenticationyes #开启此行

UsePAM yes #添加此行

Service sshd restart

5. 生成google-authenticator配置

google-authenticator

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

https://www.google.com/chart?chs=200x200&chld=M|0&cht=qr&chl=otpauth://totp/[email protected]%3Fsecret%3DABEXG5K6CVB56BXY

#此网址为生成的二维码,客户端扫描

Your newsecret key is:node3.mengtao.com

Yourverification code is 582849

Youremergency scratch codes are:

30776626

14200155

80795568

23936997

21919909

#上面几行数字为应急码

Do youwant me to update your "/root/.google_authenticator" file (y/n) y

#更新配置文件

Do youwant to disallow multiple uses of the same authentication

token?This restricts you to one login about every 30s, but it increases

yourchances to notice or even prevent man-in-the-middle attacks (y/n) y

#禁止一个口令多用

Bydefault, tokens are good for 30 seconds and in order to compensate for

possibletime-skew between the client and the server, we allow an extra

tokenbefore and after the current time. If you experience problems with poor

timesynchronization, you can increase the window from its default

size of1:30min to about 4min. Do you want to do so (y/n) n

#客户端与服务器时间误差

If thecomputer that you are logging into isn‘t hardened against brute-force

loginattempts, you can enable rate-limiting for the authentication module.

Bydefault, this limits attackers to no more than 3 login attempts every 30s.

Do youwant to enable rate-limiting (y/n) y

#次数限制

在设备上输入序列码和扫描二维码都可以

6. 登录验证

时间: 2024-07-31 17:25:52

SSH使用Google Authenticator二次验证的相关文章

谷歌上google authenticator二次验证

参考: GA安装: https://www.cnblogs.com/hanyifeng/p/kevin4real.html https://shenyu.me/2016/09/05/centos-google-authenticator.html https://www.howtoing.com/secure-ssh-with-google-authenticator-on-centos-7 原理: https://en.wikipedia.org/wiki/Google_Authenticat

Google authenticator 谷歌身份验证,实现动态口令

google authenticator php 服务端 使用PHP类 require_once '../PHPGangsta/GoogleAuthenticator.php'; $ga = new PHPGangsta_GoogleAuthenticator(); //创建一个新的"安全密匙SecretKey" //把本次的"安全密匙SecretKey" 入库,和账户关系绑定,客户端也是绑定这同一个"安全密匙SecretKey" $secret

google authenticator 谷歌身份验证器

How to add extra security to your MVC web application, using two factor authentication. Download source code - 2.8 MB What is Two Factor Authentication? Two Factor Authentication is a way to authenticate users using two of the three valid authenticat

Google Authenticator SSH双重验证技术

    Technology - Site OPS Google Authenticator SSH双重验证技术 管理手册 目  录 第1章引言... 1 1.1 目的... 1 1.2 说明... 1 第2章 SSH 双重验证实现... 2 2.1 基础工作... 2 2.2 配置工作... 2 第3章手机客户端配置... 4 第4章 SSH 登录验证... 6 4.1XSHELL 登录验证... 6 4.2 跳板机登录... 7 4.3 总结... 8 第1章 引言 1.1 目的 SSH 安

使用Google Authenticator给ssh进行登录验证

普通情况下的服务器登录,是"服务器+密码"这种直白的验证方式,但是这种方式太过简单,一旦密码泄露,服务器就有危险,于是为了安全我们就要在登录上再加一把锁,那就是使用Google Authenticator(谷歌身份验证器)这个工具,在登录的时候进行一次验证,只有"验证通过了"+"密码正确"才能登陆服务器. 安装前准备: 1)关闭Selinux :#setenforce 0 2)安装依赖:#yum -y install gcc make pam-d

使用Google身份验证进行ssh二次验证

什么是谷歌身份验证器 谷歌身份验证器,即Google Authenticator(Google身份验证器)v2.33 谷歌推出的一款动态口令工具,解决大家的google账户遭到恶意攻击的问题. 特点 1.透过QR图码自动设定2.支持多个账户3.支援多种语言 开始动手 1.编辑/etc/selinux/config文件,关闭selinuxSELINUX=disabled 2.yum安装相关程序yum -y install gcc make pam-devel libpng-devel libtoo

java实现谷歌二步验证 (Google Authenticator)

准备: 一个谷歌二步验证APP,  我用的是ios 身份宝 资料: 1.Google Authenticator 原理及Java实现   //主要参考 https://blog.csdn.net/lizhengjava/article/details/76947962# 2.谷歌验证 (Google Authenticator) 的实现原理是什么? https://www.zhihu.com/question/20462696 3.谷歌验证,又称两步验证, https://www.360shou

Linux实现ssh双因子登陆,with Google Authenticator

之前听别人说,用了XX家的云,安装一个手机APP,每次登陆需要先验证动态密码,再输入密码,安全性大大提高,实现了传说中的双因子登陆,当时觉得好洋气. 因为之前关注的角度不同,我更多的是从登陆统计以及报警来观察,毕竟让你直接登陆的堡垒机或者跳板机并不多,是我太out,听说过双因子登陆却一直没有去行动,于是心血来潮详细百度谷歌了一些文章,更多的都是通过添加第三方模块增加二次验证,于是几个较为出名的就来了:谷歌认证google-authenticator,freeotp,洋葱令牌,对比了一下名字,发现

CentOS 使用 Google Authenticator 登录验证

手机上安装Google身份验证器 安装地址:http://www.wandoujia.com/apps/com.google.android.apps.authenticator2 注意:机器上一定要关闭selinux 1.安装依赖: yum -y install gcc make pam-devel libpng-devel libtool wget git 2.开启EPEL源 yum –enablerepo=epel 3.或者直接安装EPEL源RPM包 # CentOS 6 rpm -Uvh