CentOS7下利用Google Authenticator实现SSH登录的二次身份验证

简介: CentOS7下利用Google Authenticator实现SSH登录的二次身份验证

640.jpg

Google Authenticator(谷歌身份验证器),是谷歌公司推出的一款动态令牌工具,解决账户使用时遭到的一些不安全的操作进行的“二次验证”,认证器基于RFC文档中的HOTP/TOTP算法实现 ,是一种从共享秘钥和时间或次数一次性令牌的算法。在实际应用中可以通过认证器方式对账户有更好的保护

下面在CentOS7下利用Google Authenticator实现SSH登录的二次身份验证


1、配置EPEL源


curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo
curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
yum makecache

image.png


2、安装Google Authenticator


yum install google-authenticator -y

640.png

3、安装Google Authenticator


useradd yuanfan
passwd yuanfan
su - yuanfan
google-authenticator
Your new secret key is: G5RR2IJG2X74MI4ADW622R6PUA 
#如果在手机的谷歌身份验证器上不想通过"扫描条形码"的方式添加,就输入这个key,通过"手动输入验证码的方式"
Your verification code is 906194
Your emergency scratch codes are:  
#下面会生成5个紧急验证码(当无法获取动态验证码或验证码不能使用时可以使用这5个),
#需要注意的是:这5个验证码用一个就会少一个!请保存好!
  45731126
  22009120
  27836115
  94685459
  48945214
Do you want me to update your "/home/yuanfan/.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, 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 
#默认动态验证码在30秒内有效,由于客户端和服务器可能会存在时间差,可将时间增加到最长4分钟,是否要这么做:这里选择y
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进行限制


640.png


640.png

640.png

4、修改SSH登录相关配置文件参数


如下行添加如下参数


vim /etc/pam.d/sshd  (如下位置增加下面一行)
auth required pam_google_authenticator.so
vim /etc/ssh/sshd_config 
将ChallengeResponseAuthentication修改为yes
ChallengeResponseAuthentication yes
service sshd restart


640.png

640.png

640.png


5、手机下载google身份验


以安卓手机为例 扫描QR码方式来进行绑定

640.jpg640.jpg

640.jpg640.jpg


6、登录验证测试


ssh yuanfan@localhost


然后输入手机google身份验证器生成的动态验证码(每30秒更新一次)

640.png

SecureCRT登录时,将Keyboard Interactive登录方式调整为第一个位置


640.png

640.png

640.png

640.png

640.png

注意,如果没有用root用户进行第三步的操作,需要先其它用户登录后su root切换到root


https://wiki.archlinux.org/index.php/Google_Authenticator

相关文章
|
9月前
|
应用服务中间件 网络安全 数据安全/隐私保护
网关服务器配置指南:实现自动DHCP地址分配、HTTP服务和SSH无密码登录。
哇哈哈,道具都准备好了,咱们的魔术秀就要开始了。现在,你的网关服务器已经魔法满满,自动分配IP,提供网页服务,SSH登录如入无人之境。而整个世界,只会知道效果,不会知道是你在幕后操控一切。这就是真正的数字世界魔法师,随手拈来,手到擒来。
471 14
|
网络协议 Linux 网络安全
微软工程师偷偷在用!这款SSH工具让Windows操控CentOS比Mac还优雅!
远程登录Linux服务器是管理和维护服务器的重要手段,尤其在远程办公、云服务管理等场景中不可或缺。通过工具如XShell,用户可以方便地进行远程管理。SSH协议确保了数据传输的安全性,命令行界面提高了操作效率。配置XShell连接CentOS时,需确保Linux系统开启sshd服务和22端口,并正确设置主机地址、用户名和密码。此外,调整字体和配色方案可优化使用体验,解决中文显示问题。
529 21
微软工程师偷偷在用!这款SSH工具让Windows操控CentOS比Mac还优雅!
|
11月前
|
安全 Linux 网络安全
在Linux(CentOS和AWS)上安装更新的git2的方法并配置github-ssh
经过以上这些步骤,你现在就能在GitHub上顺利往返,如同海洋中的航海者自由驰骋。欢迎你加入码农的世界,享受这编程的乐趣吧!
482 10
|
JavaScript 应用服务中间件 Linux
【应用服务 App Service】解决无法从Azure门户SSH登录问题
【应用服务 App Service】解决无法从Azure门户SSH登录问题
325 0
|
安全 Linux 网络安全
CentOS 8下SSH连接超时与“无法加载主机密钥”错误的排查与修复
在CentOS 8系统中,宝塔面板提示“出错了,面板运行时发生错误”,导致插件无法正常显示。同时,SSH连接超时,修复面板功能失效。通过VNC连接排查,发现SSH服务安装和配置问题频发,最终通过重装SSH、调整权限并重新生成主机密钥文件解决问题,成功恢复SSH连接。
951 16
|
安全 网络安全 数据安全/隐私保护
Debian 12系统中允许Root远程SSH登录解决方法!
在 Debian 12 系统中开启 SSH 远程 Root 登录需修改 SSH 配置文件 (`sshd_config`),将 `PermitRootLogin` 设置为 `yes` 并确保密码认证启用。完成后重启 SSH 服务并验证连接。若防火墙启用,需放行端口 22。注意,直接开放 Root 登录可能带来安全风险,建议使用普通用户登录后切换至 Root。
1783 1
|
Linux 网络安全 数据安全/隐私保护
配置ssh免密登录
配置ssh免密登录
777 106
|
监控 Ubuntu 安全
debian或Ubuntu中开启ssh允许root远程ssh登录的方法
在Debian或Ubuntu系统中启用root用户的SSH远程登录需要编辑SSH配置文件、设置root密码并重启SSH服务。虽然这可以在某些情况下提供便利,但必须注意安全性,通过使用强密码、限制IP访问、使用SSH密钥认证等方法来保护服务器的安全。
6653 5
|
机器学习/深度学习 存储 Linux
【机器学习 Azure Machine Learning】使用VS Code登录到Linux VM上 (Remote-SSH), 及可直接通过VS Code编辑VM中的文件
【机器学习 Azure Machine Learning】使用VS Code登录到Linux VM上 (Remote-SSH), 及可直接通过VS Code编辑VM中的文件
362 4
|
安全 Shell Linux
如何禁止某个用户使用ssh登录
本文介绍了五种禁止用户通过SSH登录的方法:1) 修改`/etc/ssh/sshd_config`文件中的`DenyUsers`和`DenyGroups`来阻止特定用户或用户组登录;2) 将用户的默认shell设置为`/usr/sbin/nologin`或`/bin/false`以禁用其SSH访问;3) 利用PAM(可插入认证模块)通过编辑`/etc/security/sshd.conf`来限制登录权限;4) 通过编辑`/etc/hosts.deny`文件拒绝特定用户的SSH访问;5) 锁定或禁用用户账号以阻止所有类型的登录。每种方法都提供了详细的步骤指导。
2450 1