IT数码 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁
 
   -> 系统运维 -> 配置 SSH 双因素认证 -> 正文阅读

[系统运维]配置 SSH 双因素认证

??????运维工程师必备的认证【红帽liunx-RHCE 8】_XMWS_IT的博客-CSDN博客_运维工程师考什么证书RHCE试听课程:linux系统下,用这个命令可以提高60%的工作效率https://mp.weixin.qq.com/s/pZVjMI1PLJzrA8hoPzkgMA红帽RHCE试听课程:如何快速实现对服务器密码爆破?https://mp.weixin.qq.com/s/JUpf8G86jvnNwvKLUfWcLQ红帽RHCE 8.0课程介绍一、目标学员为之前没有 Linux? 系统管理经验的 IT 从业人员而设计。本课程侧重讲解Linux 系统的核心管理任务,为学员提供系统管理的必备“生https://blog.csdn.net/XMWS_IT/article/details/118357903?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522165389341716781435484878%2522%252C%2522scm%2522%253A%252220140713.130102334.pc%255Fblog.%2522%257D&request_id=165389341716781435484878&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~blog~first_rank_ecpm_v1~rank_v31_ecpm-1-118357903-null-null.nonecase&utm_term=RHCE&spm=1018.2226.3001.4450
什么是双因素认证

Two Factor Authentication 简称 "2FA"; 通过组合2种不同的验证方式来进行用户身份验证的机制

即用户需要通过2种不同的方式进行认证

  • 服务器本身的用户名/密码

  • 借助其他工具提供用户预先不知道的信息(如短信验证码、银行的电子令牌等等...)


?

主流双因素认证使用的技术

TOTP, Time base One-time Password 基于时间的一次性密码,是公认可靠的解决方案(RFC 6238)

常用的工具: Google Authenticator(支持 Linux/Android/IOS 自行下载)

附件: Android 版本


?

实验


在 CentOS 7/8 上对 ssh 使用双因素认证

1.安装 google-authenticator

[root@localhost?~]#?yum?-y?install?epel-release
[root@localhost?~]#?yum?-y?install?google-authenticator


2.配置 google-authenticator

[root@localhost?~]#?google-authenticator
Do?you?want?authentication?tokens?to?be?time-based?(y/n)?y
Warning:?pasting?the?following?URL?into?your?browser?exposes?the?OTP?secret?to?Google:
https://www.google.com/chart?chs=200x200&chld=M|0&cht=qr&chl
=otpauth://totp/root@localhost.localdomain%3Fsecret%3DK3L4YTH2WPE2DOJLVMJGYH5RII%26issuer%3Dlocalhost.localdomain
![](https://files.mdnice.com/user/30567/553658bb-3c3b-453e-a86b-ecb40ff921cd.png)
Your?new?secret?key?is:?K3L4YTH2WPE2DOJLVMJGYH5RII
Your?verification?code?is?538087
Your?emergency?scratch?codes?are:
86712045
77396403
32965136
37749850
76399812
Do?you?want?me?to?update?your?"/root/.google_authenticator"?file??(y/n)?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)?n
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
[root@localhost?~]#


解释配置

3.打开手机上的 google-authenticator,扫描上面的二维码后,软件就能自动显示出数字令牌(由于无法截图,没法展示)


4.查看 google-authenticator 提供的 PAM 模块路径

[root@localhost?~]#?rpm?-ql?google-authenticator?|?grep?pam
/usr/lib64/security/pam_google_authenticator.la
/usr/lib64/security/pam_google_authenticator.so
/usr/share/man/man8/pam_google_authenticator.8.gz


5.编辑 /etc/pam.d/sshd 文件,在文件内容最后一行添加

#%PAM-1.0
auth?required?pam_sepermit.so
auth?substack?password-auth
auth?include?postlogin
#?Used?with?polkit?to?reauthorize?users?in?remote?sessions
-auth?optional?pam_reauthorize.so?prepare
account?required?pam_nologin.so
account?include?password-auth
password?include?password-auth
#?pam_selinux.so?close?should?be?the?first?session?rule
session?required?pam_selinux.so?close
session?required?pam_loginuid.so
#?pam_selinux.so?open?should?only?be?followed?by?sessions?to?be?executed?in?the?user?context
session?required?pam_selinux.so?open?env_params
session?required?pam_namespace.so
session?optional?pam_keyinit.so?force?revoke
session?include?password-auth
session?include?postlogin
#?Used?with?polkit?to?reauthorize?users?in?remote?sessions
-session?optional?pam_reauthorize.so?prepare
auth?required?/usr/lib64/security/pam_google_authenticator.so


6.修改 ssh 配置文件 /etc/ssh/sshd_config, 将 ChallengeResponseAuthentication no 改为 yes

ChallengeResponseAuthentication?yes


7.重启 sshd 服务

[root@localhost?~]#?systemctl?restart?sshd

8.此时使用 XShell 登录,必须要使用 "Keyboard Interactive" 方式; 先输入密码,然后输入令牌,正确后才能登录系统



一次性紧急登录代码

google_authenticator 的配置文件默认在 ~/.google_authenticator

[root@localhost?~]#?cat?.google_authenticator
K3L4YTH2WPE2DOJLVMJGYH5RII
"?RATE_LIMIT?3?30?1652456528
"?DISALLOW_REUSE?55081884
"?TOTP_AUTH
86712045
77396403
32965136
37749850
76399812
[root@localhost?~]#

如遇到不可抗力的情况,需要登录系统,可以使用紧急代码进行临时登录,上图绿色字体部分; 用完即永久失效, 文件中的紧急代码会被删除掉;

但可以自己手动添加紧急代码,建议自行手动多加几个自己记得住的紧急代码

  系统运维 最新文章
配置小型公司网络WLAN基本业务(AC通过三层
如何在交付运维过程中建立风险底线意识,提
快速传输大文件,怎么通过网络传大文件给对
从游戏服务端角度分析移动同步(状态同步)
MySQL使用MyCat实现分库分表
如何用DWDM射频光纤技术实现200公里外的站点
国内顺畅下载k8s.gcr.io的镜像
自动化测试appium
ctfshow ssrf
Linux操作系统学习之实用指令(Centos7/8均
上一篇文章      下一篇文章      查看所有文章
加:2022-06-06 17:33:28  更:2022-06-06 17:34:40 
 
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁

360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年5日历 -2024/5/19 1:04:39-

图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT数码