SSH 安全加固篇:通过“运维密码”小程序实现 SSH 双因子认证

找不到分类 evilven 6个月前 (04-08) 68次浏览 未收录 0个评论 扫描二维码
SSH 安全加固篇:通过“运维密码”小程序实现 SSH 双因子认证

本文讲述了如何通过 Linux中国 所开发的微信小程序“运维密码”实现在 Linux 系统上 OpenSSH 双因子认证,从而对 SSH 进行安全加固。
— netb2c


本文导航

 作者 | netb2c

本文讲述了如何通过 Linux中国 所开发的微信小程序“运维密码[1]”实现在 Linux 系统上 OpenSSH 双因子认证,从而对 SSH 进行安全加固。

背景

近来很多知名企业都出现了密码泄露,通过单一的密码对敏感和重要信息进行保护已经面临越来越多的挑战,因此业内对多重认证的呼声也越来越高,而其中的双因子认证得到了业界的普遍认可。

什么是双因子认证

双因子认证Two-factor authentication(即 2FA),是一种通过组合两种不同的验证方式进行用户身份验证的机制。

在这种多重认证的系统中,用户需要通过两种不同的认证程序:

  • 提供他们知道的信息(如用户名/密码)

  • 再借助其他工具提供用户所不知道的信息(如用手机生成的一次性密码)

SSH 双因子认证实现思路

在 SSH 服务器端安装 Google 身份验证器服务器端组件,这样,在使用密码或密钥登录 SSH 服务器时,同时通过与 Google 身份验证器相匹配的客户端所提供的验证信息来确认登录者的身份和权限。这里的客户端可以使用Google 身份验证器Google Authenticator[2]应用,也可以使用我们开发的、采用同一个 RFC 规范的“运维密码”微信小程序。

Google 身份验证器所采用的算法规范基于 TOTP RFC 草案[3]

(题外话,RSA 硬件令牌,也是采用了类似的机制,只不过客户端是硬件的;而最近 Apple 公司的一些服务所需要的双因子认证也是一样的,但是其用于呈现验证信息的是手机或平板上的 iOS 内部组件,非独立应用。)

关于Google 身份验证器

为了鼓励广泛采用双因子认证的方式,Google 公司发布了Google 身份验证器Google Authenticator[4],这是一款开源的、可基于开放规则(如 HMAP/ 基于时间)生成一次性密码的软件。它是一款跨平台软件,可运行在 Linux、Android、iOS 上。Google 公司同时也支持插件式鉴别模块pluggable authentication module PAM ,使其能和其它适用于 PAM 进行验证的工具(如 OpenSSH)协同工作。

Google 身份验证器分为两个部分,分别是服务器端组件和客户端应用,都称之为“Google 身份验证器”,这里,我们为了澄清起见,会在说明时指明。

关于运维密码

Google 公司所开发的身份验证器以简洁著称,但也因此缺乏一些必要的特性,比如备份功能——这使得使用该身份验证器的人时时处于手机丢失的恐慌之中。(虽然 Google 提供的服务器端和自身的服务也提供了紧急验证码,以用于这种情况下的自救,但是很多采用 Google 身份验证器的服务并不支持和提供紧急验证码)

作为一家紧密关注于运维安全、积极倡导信息安全的技术社区,Linux 中国 久已有开发一个新的替代品的想法。恰逢微信推出小程序平台,我们感觉到这正是一个良机,可以充分利用到微信和小程序的便利之处,又适合小程序的使用情境。因此,由 Linux 中国旗下的 LCTT 技术组的白宦成同学独立开发了一款旨在移动互联网场景中提供更好的多因子认证体验的小程序:运维密码[5]

顺便说一句,在产品初步成熟之后,我们已经将该小程序开源给社区,代码托管于 GitHub:https://github.com/LCTT/WeApp-Password ,希望更多的人能够受益和共同完善它,有什么功能需求、错误反馈请到 GitHub 上提出 issue,也欢迎发送拉取请求给我们。

此外,大家在使用过程中,发现什么问题或需要帮助,也可以加入微信体验群:

SSH 安全加固篇:通过“运维密码”小程序实现 SSH 双因子认证

或添加开发者的微信号:ixiqin_com ,添加备注:“运维密码”,直接与开发者沟通。

言归正传,我们来看看如何使用“运维密码”来为你的 SSH 服务提供双因子认证支持。

如何开始

首先我们需要一些准备工作:

  • 一台运行着 OpenSSH 服务(版本大于 6.2)的 Linux 主机

  • 一台能运行微信的智能手机

  • 一台支持 SSH 登录的终端

在 Linux 系统中安装 Google 身份验证器服务器端组件

第一步需要在运行着 OpenSSH 服务的 Linux 主机上安装 Google 身份验证器服务器端组件。按照如下步骤安装 Google 身份验证器及其 PAM 模块。

用安装包安装 Google 身份验证器服务器端组件

如果你不想自己构建 Google 身份验证器服务器端组件,在几个主流 Linux 发行版上有已经编译好的安装包。安装包里面包含 Google 身份验证器服务器端组件的二进制程序和 PAM 模块。

在 Ubuntu 上安装 Google 身份验证器服务器端组件:

<ol class="linenums list-paddingleft-2" style="word-wrap: break-word; margin: 1em 2em; padding: 1px; border-left: 2px solid rgb(0, 153, 0); background-image: none; color: rgb(174, 174, 174); line-height: 1.2em; font-size: 9px;"><li><p><code style="word-wrap: break-word; background: none; text-shadow: rgb(0, 0, 0) 0px 1px 1px; color: rgb(184, 255, 184); line-height: 1.2em; padding-left: 10px !important; border-radius: 0px !important; margin-top: 1em !important; margin-bottom: 1em !important; border-width: initial !important; border-style: none !important; border-color: initial !important;"><span class="kwd" style="word-wrap: break-word; color: rgb(226, 137, 100);">sudo</span><span class="pln" style="word-wrap: break-word;"> </span><span class="kwd" style="word-wrap: break-word; color: rgb(226, 137, 100);">apt-get</span><span class="pln" style="word-wrap: break-word;"> install libpam</span><span class="pun" style="word-wrap: break-word;">-</span><span class="pln" style="word-wrap: break-word;">google</span><span class="pun" style="word-wrap: break-word;">-</span><span class="pln" style="word-wrap: break-word;">authenticator</span></code></p></li></ol>

在 Fedora 上安装 Google 身份验证器服务器端组件:

<ol class="linenums list-paddingleft-2" style="word-wrap: break-word; margin: 1em 2em; padding: 1px; border-left: 2px solid rgb(0, 153, 0); background-image: none; color: rgb(174, 174, 174); line-height: 1.2em; font-size: 9px;"><li><p><code style="word-wrap: break-word; background: none; text-shadow: rgb(0, 0, 0) 0px 1px 1px; color: rgb(184, 255, 184); line-height: 1.2em; padding-left: 10px !important; border-radius: 0px !important; margin-top: 1em !important; margin-bottom: 1em !important; border-width: initial !important; border-style: none !important; border-color: initial !important;"><span class="kwd" style="word-wrap: break-word; color: rgb(226, 137, 100);">sudo</span><span class="pln" style="word-wrap: break-word;"> dnf install google</span><span class="pun" style="word-wrap: break-word;">-</span><span class="pln" style="word-wrap: break-word;">authenticator</span></code></p></li></ol>

在 CentOS 上安装 Google 身份验证器服务器端组件,需要首先启用 EPEL 软件库[6],然后运行如下命令:

<ol class="linenums list-paddingleft-2" style="word-wrap: break-word; margin: 1em 2em; padding: 1px; border-left: 2px solid rgb(0, 153, 0); background-image: none; color: rgb(174, 174, 174); line-height: 1.2em; font-size: 9px;"><li><p><code style="word-wrap: break-word; background: none; text-shadow: rgb(0, 0, 0) 0px 1px 1px; color: rgb(184, 255, 184); line-height: 1.2em; padding-left: 10px !important; border-radius: 0px !important; margin-top: 1em !important; margin-bottom: 1em !important; border-width: initial !important; border-style: none !important; border-color: initial !important;"><span class="kwd" style="word-wrap: break-word; color: rgb(226, 137, 100);">sudo</span><span class="pln" style="word-wrap: break-word;"> </span><span class="kwd" style="word-wrap: break-word; color: rgb(226, 137, 100);">yum</span><span class="pln" style="word-wrap: break-word;"> install google</span><span class="pun" style="word-wrap: break-word;">-</span><span class="pln" style="word-wrap: break-word;">authenticator</span></code></p></li></ol>

编译安装 Google 身份验证器服务器端组件

首先,安装构建 Google 身份验证器所需的软件包。

在 Debian、 Ubuntu 或 Linux Mint 上:

<ol class="linenums list-paddingleft-2" style="word-wrap: break-word; margin: 1em 2em; padding: 1px; border-left: 2px solid rgb(0, 153, 0); background-image: none; color: rgb(174, 174, 174); line-height: 1.2em; font-size: 9px;"><li><p><code style="word-wrap: break-word; background: none; text-shadow: rgb(0, 0, 0) 0px 1px 1px; color: rgb(184, 255, 184); line-height: 1.2em; padding-left: 10px !important; border-radius: 0px !important; margin-top: 1em !important; margin-bottom: 1em !important; border-width: initial !important; border-style: none !important; border-color: initial !important;"><span class="kwd" style="word-wrap: break-word; color: rgb(226, 137, 100);">sudo</span><span class="pln" style="word-wrap: break-word;"> </span><span class="kwd" style="word-wrap: break-word; color: rgb(226, 137, 100);">apt-get</span><span class="pln" style="word-wrap: break-word;"> install </span><span class="kwd" style="word-wrap: break-word; color: rgb(226, 137, 100);">wget</span><span class="pln" style="word-wrap: break-word;"> </span><span class="kwd" style="word-wrap: break-word; color: rgb(226, 137, 100);">make</span><span class="pln" style="word-wrap: break-word;"> </span><span class="kwd" style="word-wrap: break-word; color: rgb(226, 137, 100);">gcc</span><span class="pln" style="word-wrap: break-word;"> libpam0g</span><span class="pun" style="word-wrap: break-word;">-</span><span class="pln" style="word-wrap: break-word;">dev</span></code></p></li></ol>

在 CentOS、 Fedora 或 RHEL 上:

<ol class="linenums list-paddingleft-2" style="word-wrap: break-word; margin: 1em 2em; padding: 1px; border-left: 2px solid rgb(0, 153, 0); background-image: none; color: rgb(174, 174, 174); line-height: 1.2em; font-size: 9px;"><li><p><code style="word-wrap: break-word; background: none; text-shadow: rgb(0, 0, 0) 0px 1px 1px; color: rgb(184, 255, 184); line-height: 1.2em; padding-left: 10px !important; border-radius: 0px !important; margin-top: 1em !important; margin-bottom: 1em !important; border-width: initial !important; border-style: none !important; border-color: initial !important;"><span class="kwd" style="word-wrap: break-word; color: rgb(226, 137, 100);">sudo</span><span class="pln" style="word-wrap: break-word;"> </span><span class="kwd" style="word-wrap: break-word; color: rgb(226, 137, 100);">yum</span><span class="pln" style="word-wrap: break-word;"> install </span><span class="kwd" style="word-wrap: break-word; color: rgb(226, 137, 100);">wget</span><span class="pln" style="word-wrap: break-word;"> </span><span class="kwd" style="word-wrap: break-word; color: rgb(226, 137, 100);">make</span><span class="pln" style="word-wrap: break-word;"> </span><span class="kwd" style="word-wrap: break-word; color: rgb(226, 137, 100);">gcc</span><span class="pln" style="word-wrap: break-word;"> pam</span><span class="pun" style="word-wrap: break-word;">-</span><span class="pln" style="word-wrap: break-word;">devel</span></code></p></li></ol>

然后下载 Google 身份验证器服务器端组件的源代码:

<ol class="linenums list-paddingleft-2" style="word-wrap: break-word; margin: 1em 2em; padding: 1px; border-left: 2px solid rgb(0, 153, 0); background-image: none; color: rgb(174, 174, 174); line-height: 1.2em; font-size: 9px;"><li><p><code style="word-wrap: break-word; background: none; text-shadow: rgb(0, 0, 0) 0px 1px 1px; color: rgb(184, 255, 184); line-height: 1.2em; padding-left: 10px !important; border-radius: 0px !important; margin-top: 1em !important; margin-bottom: 1em !important; border-width: initial !important; border-style: none !important; border-color: initial !important;"><span class="kwd" style="word-wrap: break-word; color: rgb(226, 137, 100);">git</span><span class="pln" style="word-wrap: break-word;"> </span><span class="kwd" style="word-wrap: break-word; color: rgb(226, 137, 100);">clone</span><span class="pln" style="word-wrap: break-word;"> https</span><span class="pun" style="word-wrap: break-word;">:</span><span class="com" style="word-wrap: break-word; color: rgb(174, 174, 174); font-style: italic;">//github.com/google/google-authenticator.git</span></code></p></li></ol>

编译安装 Google 身份验证器服务器端组件:

<ol class="linenums list-paddingleft-2" style="word-wrap: break-word; margin: 1em 2em; padding: 1px; border-left: 2px solid rgb(0, 153, 0); background-image: none; color: rgb(174, 174, 174); line-height: 1.2em; font-size: 9px;">
<li><p><code style="word-wrap: break-word; background: none; text-shadow: rgb(0, 0, 0) 0px 1px 1px; color: rgb(184, 255, 184); line-height: 1.2em; padding-left: 10px !important; border-radius: 0px !important; margin-top: 1em !important; margin-bottom: 1em !important; border-width: initial !important; border-style: none !important; border-color: initial !important;"><span class="kwd" style="word-wrap: break-word; color: rgb(226, 137, 100);">cd</span><span class="pln" style="word-wrap: break-word;"> google</span><span class="pun" style="word-wrap: break-word;">-</span><span class="pln" style="word-wrap: break-word;">authenticator</span><span class="pun" style="word-wrap: break-word;">/</span><span class="pln" style="word-wrap: break-word;">libpam</span></code></p></li>
<li><p><code style="word-wrap: break-word; background: none; text-shadow: rgb(0, 0, 0) 0px 1px 1px; color: rgb(184, 255, 184); line-height: 1.2em; padding-left: 10px !important; border-radius: 0px !important; margin-top: 1em !important; margin-bottom: 1em !important; border-width: initial !important; border-style: none !important; border-color: initial !important;"></code></p></li>
<li><p><code style="word-wrap: break-word; background: none; text-shadow: rgb(0, 0, 0) 0px 1px 1px; color: rgb(184, 255, 184); line-height: 1.2em; padding-left: 10px !important; border-radius: 0px !important; margin-top: 1em !important; margin-bottom: 1em !important; border-width: initial !important; border-style: none !important; border-color: initial !important;"><span class="pun" style="word-wrap: break-word;">./</span><span class="pln" style="word-wrap: break-word;">bootstrap</span><span class="pun" style="word-wrap: break-word;">.</span><span class="pln" style="word-wrap: break-word;">sh</span></code></p></li>
<li><p><code style="word-wrap: break-word; background: none; text-shadow: rgb(0, 0, 0) 0px 1px 1px; color: rgb(184, 255, 184); line-height: 1.2em; padding-left: 10px !important; border-radius: 0px !important; margin-top: 1em !important; margin-bottom: 1em !important; border-width: initial !important; border-style: none !important; border-color: initial !important;"><span class="pun" style="word-wrap: break-word;">./</span><span class="pln" style="word-wrap: break-word;">configure</span></code></p></li>
<li><p><code style="word-wrap: break-word; background: none; text-shadow: rgb(0, 0, 0) 0px 1px 1px; color: rgb(184, 255, 184); line-height: 1.2em; padding-left: 10px !important; border-radius: 0px !important; margin-top: 1em !important; margin-bottom: 1em !important; border-width: initial !important; border-style: none !important; border-color: initial !important;"></code></p></li>
<li><p><code style="word-wrap: break-word; background: none; text-shadow: rgb(0, 0, 0) 0px 1px 1px; color: rgb(184, 255, 184); line-height: 1.2em; padding-left: 10px !important; border-radius: 0px !important; margin-top: 1em !important; margin-bottom: 1em !important; border-width: initial !important; border-style: none !important; border-color: initial !important;"><span class="kwd" style="word-wrap: break-word; color: rgb(226, 137, 100);">make</span></code></p></li>
</ol>

如果构建成功,你会在目录中看到 pam_google_authenticator.so 和 google-authenticator 两个二进制文件。

最后,将 Google 身份验证器的服务器端组件安装到合适位置。其默认会安装到 /usr/local/lib/security 下,根据你的系统不同,你可能需要将其符号链接到 pam 库的位置(比如 CentOS 7 会在 /usr/lib64/security)。如下图所示:

SSH 安全加固篇:通过“运维密码”小程序实现 SSH 双因子认证

<ol class="linenums list-paddingleft-2" style="word-wrap: break-word; margin: 1em 2em; padding: 1px; border-left: 2px solid rgb(0, 153, 0); background-image: none; color: rgb(174, 174, 174); line-height: 1.2em; font-size: 9px;"><li><p><code style="word-wrap: break-word; background: none; text-shadow: rgb(0, 0, 0) 0px 1px 1px; color: rgb(184, 255, 184); line-height: 1.2em; padding-left: 10px !important; border-radius: 0px !important; margin-top: 1em !important; margin-bottom: 1em !important; border-width: initial !important; border-style: none !important; border-color: initial !important;"><span class="kwd" style="word-wrap: break-word; color: rgb(226, 137, 100);">sudo</span><span class="pln" style="word-wrap: break-word;"> </span><span class="kwd" style="word-wrap: break-word; color: rgb(226, 137, 100);">make</span><span class="pln" style="word-wrap: break-word;"> install</span></code></p></li></ol>

至此,Google 身份验证器服务器端组件安装完成。

配置 Google 身份验证器服务器端组件及“运维密码”小程序

完成 Google 身份验证器服务器端组件的安装我们仅仅完成了第一步,接着需要对 Google 身份验证器服务器端组件、“运维密码”、OpenSSH 进行配置才能达到我们预期的效果。

配置 google-authenticator 及生成验证密钥

使用以下命令生成验证密钥:

<ol class="linenums list-paddingleft-2" style="word-wrap: break-word; margin: 1em 2em; padding: 1px; border-left: 2px solid rgb(0, 153, 0); background-image: none; color: rgb(174, 174, 174); line-height: 1.2em; font-size: 9px;"><li><p><code style="word-wrap: break-word; background: none; text-shadow: rgb(0, 0, 0) 0px 1px 1px; color: rgb(184, 255, 184); line-height: 1.2em; padding-left: 10px !important; border-radius: 0px !important; margin-top: 1em !important; margin-bottom: 1em !important; border-width: initial !important; border-style: none !important; border-color: initial !important;"><span class="pun" style="word-wrap: break-word;">./</span><span class="pln" style="word-wrap: break-word;">google</span><span class="pun" style="word-wrap: break-word;">-</span><span class="pln" style="word-wrap: break-word;">authenticator </span></code></p></li></ol>

生成验证密钥的时候,会再次确认信息。

<ol class="linenums list-paddingleft-2" style="word-wrap: break-word; margin: 1em 2em; padding: 1px; border-left: 2px solid rgb(0, 153, 0); background-image: none; color: rgb(174, 174, 174); line-height: 1.2em; font-size: 9px;"><li><p><code style="word-wrap: break-word; background: none; text-shadow: rgb(0, 0, 0) 0px 1px 1px; color: rgb(184, 255, 184); line-height: 1.2em; padding-left: 10px !important; border-radius: 0px !important; margin-top: 1em !important; margin-bottom: 1em !important; border-width: initial !important; border-style: none !important; border-color: initial !important;"><span class="typ" style="word-wrap: break-word; color: rgb(137, 189, 255);">Do</span><span class="pln" style="word-wrap: break-word;"> you want authentication tokens to be </span><span class="kwd" style="word-wrap: break-word; color: rgb(226, 137, 100);">time</span><span class="pun" style="word-wrap: break-word;">-</span><span class="pln" style="word-wrap: break-word;">based </span><span class="pun" style="word-wrap: break-word;">(</span><span class="pln" style="word-wrap: break-word;">y</span><span class="pun" style="word-wrap: break-word;">/</span><span class="pln" style="word-wrap: break-word;">n</span><span class="pun" style="word-wrap: break-word;">)</span></code></p></li></ol>

意思是:你想要生成基于时间生成验证码吗?这里需要需要输入 y

输入 y之后你将看到一个代表着该“场景”密钥的二维码和密钥字符串,它使用如下二维码图形格式表示我们数字形态的密钥(这里也提供了一个用于在浏览器中再次显示该二维码的 URL,但是需要翻墙)。接着我们要用到它在“运维密码”上完成配置。

SSH 安全加固篇:通过“运维密码”小程序实现 SSH 双因子认证

在二维码和密钥字符串后面,接着显示了一个当前的校验码和几个紧急密钥。紧急密钥你可以另行保存的一个安全的地方,以防你在无法使用 Google 身份验证器应用或“运维密码”时使用(紧急密钥是 8 位的,不同于普通的 6 位密钥,也是一次性使用的)。

SSH 安全加固篇:通过“运维密码”小程序实现 SSH 双因子认证

保存 Google 服务器端组件的配置文件,Google 身份验证器虽然运行了,但是相关设置还没有保存,接下来会提示保存:

<ol class="linenums list-paddingleft-2" style="word-wrap: break-word; margin: 1em 2em; padding: 1px; border-left: 2px solid rgb(0, 153, 0); background-image: none; color: rgb(174, 174, 174); line-height: 1.2em; font-size: 9px;"><li><p><code style="word-wrap: break-word; background: none; text-shadow: rgb(0, 0, 0) 0px 1px 1px; color: rgb(184, 255, 184); line-height: 1.2em; padding-left: 10px !important; border-radius: 0px !important; margin-top: 1em !important; margin-bottom: 1em !important; border-width: initial !important; border-style: none !important; border-color: initial !important;"><span class="typ" style="word-wrap: break-word; color: rgb(137, 189, 255);">Do</span><span class="pln" style="word-wrap: break-word;"> you want me to update your </span><span class="str" style="word-wrap: break-word; color: rgb(101, 176, 66);">"/root/.google_authenticator"</span><span class="pln" style="word-wrap: break-word;"> </span><span class="kwd" style="word-wrap: break-word; color: rgb(226, 137, 100);">file</span><span class="pun" style="word-wrap: break-word;">?</span><span class="pln" style="word-wrap: break-word;"> </span><span class="pun" style="word-wrap: break-word;">(</span><span class="pln" style="word-wrap: break-word;">y</span><span class="pun" style="word-wrap: break-word;">/</span><span class="pln" style="word-wrap: break-word;">n</span><span class="pun" style="word-wrap: break-word;">)</span><span class="pln" style="word-wrap: break-word;"> </span></code></p></li></ol>

意思是:你想将配置文件更新到 /root/.google_authenticator 保存吗?

输入 y 回车。

禁止同一令牌多次登录

<ol class="linenums list-paddingleft-2" style="word-wrap: break-word; margin: 1em 2em; padding: 1px; border-left: 2px solid rgb(0, 153, 0); background-image: none; color: rgb(174, 174, 174); line-height: 1.2em; font-size: 9px;">
<li><p><code style="word-wrap: break-word; background: none; text-shadow: rgb(0, 0, 0) 0px 1px 1px; color: rgb(184, 255, 184); line-height: 1.2em; padding-left: 10px !important; border-radius: 0px !important; margin-top: 1em !important; margin-bottom: 1em !important; border-width: initial !important; border-style: none !important; border-color: initial !important;"><span class="typ" style="word-wrap: break-word; color: rgb(137, 189, 255);">Do</span><span class="pln" style="word-wrap: break-word;"> you want to disallow multiple uses of the same authentication</span></code></p></li>
<li><p><code style="word-wrap: break-word; background: none; text-shadow: rgb(0, 0, 0) 0px 1px 1px; color: rgb(184, 255, 184); line-height: 1.2em; padding-left: 10px !important; border-radius: 0px !important; margin-top: 1em !important; margin-bottom: 1em !important; border-width: initial !important; border-style: none !important; border-color: initial !important;"><span class="pln" style="word-wrap: break-word;">token</span><span class="pun" style="word-wrap: break-word;">?</span><span class="pln" style="word-wrap: break-word;"> </span><span class="typ" style="word-wrap: break-word; color: rgb(137, 189, 255);">This</span><span class="pln" style="word-wrap: break-word;"> restricts you to one </span><span class="kwd" style="word-wrap: break-word; color: rgb(226, 137, 100);">login</span><span class="pln" style="word-wrap: break-word;"> about every </span><span class="lit" style="word-wrap: break-word; color: rgb(51, 135, 204);">30s</span><span class="pun" style="word-wrap: break-word;">,</span><span class="pln" style="word-wrap: break-word;"> but it increases</span></code></p></li>
<li><p><code style="word-wrap: break-word; background: none; text-shadow: rgb(0, 0, 0) 0px 1px 1px; color: rgb(184, 255, 184); line-height: 1.2em; padding-left: 10px !important; border-radius: 0px !important; margin-top: 1em !important; margin-bottom: 1em !important; border-width: initial !important; border-style: none !important; border-color: initial !important;"><span class="pln" style="word-wrap: break-word;">your chances to notice </span><span class="kwd" style="word-wrap: break-word; color: rgb(226, 137, 100);">or</span><span class="pln" style="word-wrap: break-word;"> even prevent </span><span class="kwd" style="word-wrap: break-word; color: rgb(226, 137, 100);">man</span><span class="pun" style="word-wrap: break-word;">-</span><span class="kwd" style="word-wrap: break-word; color: rgb(226, 137, 100);">in</span><span class="pun" style="word-wrap: break-word;">-</span><span class="pln" style="word-wrap: break-word;">the</span><span class="pun" style="word-wrap: break-word;">-</span><span class="pln" style="word-wrap: break-word;">middle attacks </span><span class="pun" style="word-wrap: break-word;">(</span><span class="pln" style="word-wrap: break-word;">y</span><span class="pun" style="word-wrap: break-word;">/</span><span class="pln" style="word-wrap: break-word;">n</span><span class="pun" style="word-wrap: break-word;">)</span></code></p></li>
</ol>

意思是:你是否要禁用同一密钥多次登录,这将限制你每 30 秒只能使用该密钥登录一次,但这能够让你可以更多地被提醒受到了中间人攻击,甚至能够防止这种攻击。

输入 y 回车。

时间容错设置

<ol class="linenums list-paddingleft-2" style="word-wrap: break-word; margin: 1em 2em; padding: 1px; border-left: 2px solid rgb(0, 153, 0); background-image: none; color: rgb(174, 174, 174); line-height: 1.2em; font-size: 9px;">
<li><p><code style="word-wrap: break-word; background: none; text-shadow: rgb(0, 0, 0) 0px 1px 1px; color: rgb(184, 255, 184); line-height: 1.2em; padding-left: 10px !important; border-radius: 0px !important; margin-top: 1em !important; margin-bottom: 1em !important; border-width: initial !important; border-style: none !important; border-color: initial !important;"><span class="typ" style="word-wrap: break-word; color: rgb(137, 189, 255);">By</span><span class="pln" style="word-wrap: break-word;"> </span><span class="kwd" style="word-wrap: break-word; color: rgb(226, 137, 100);">default</span><span class="pun" style="word-wrap: break-word;">,</span><span class="pln" style="word-wrap: break-word;"> tokens are good </span><span class="kwd" style="word-wrap: break-word; color: rgb(226, 137, 100);">for</span><span class="pln" style="word-wrap: break-word;"> </span><span class="lit" style="word-wrap: break-word; color: rgb(51, 135, 204);">30</span><span class="pln" style="word-wrap: break-word;"> seconds</span><span class="pun" style="word-wrap: break-word;">.</span><span class="pln" style="word-wrap: break-word;"> </span><span class="typ" style="word-wrap: break-word; color: rgb(137, 189, 255);">In</span><span class="pln" style="word-wrap: break-word;"> order to compensate </span><span class="kwd" style="word-wrap: break-word; color: rgb(226, 137, 100);">for</span></code></p></li>
<li><p><code style="word-wrap: break-word; background: none; text-shadow: rgb(0, 0, 0) 0px 1px 1px; color: rgb(184, 255, 184); line-height: 1.2em; padding-left: 10px !important; border-radius: 0px !important; margin-top: 1em !important; margin-bottom: 1em !important; border-width: initial !important; border-style: none !important; border-color: initial !important;"><span class="pln" style="word-wrap: break-word;">possible </span><span class="kwd" style="word-wrap: break-word; color: rgb(226, 137, 100);">time</span><span class="pun" style="word-wrap: break-word;">-</span><span class="pln" style="word-wrap: break-word;">skew between the client </span><span class="kwd" style="word-wrap: break-word; color: rgb(226, 137, 100);">and</span><span class="pln" style="word-wrap: break-word;"> the server</span><span class="pun" style="word-wrap: break-word;">,</span><span class="pln" style="word-wrap: break-word;"> we allow an extra</span></code></p></li>
<li><p><code style="word-wrap: break-word; background: none; text-shadow: rgb(0, 0, 0) 0px 1px 1px; color: rgb(184, 255, 184); line-height: 1.2em; padding-left: 10px !important; border-radius: 0px !important; margin-top: 1em !important; margin-bottom: 1em !important; border-width: initial !important; border-style: none !important; border-color: initial !important;"><span class="pln" style="word-wrap: break-word;">token before </span><span class="kwd" style="word-wrap: break-word; color: rgb(226, 137, 100);">and</span><span class="pln" style="word-wrap: break-word;"> after the current </span><span class="kwd" style="word-wrap: break-word; color: rgb(226, 137, 100);">time</span><span class="pun" style="word-wrap: break-word;">.</span><span class="pln" style="word-wrap: break-word;"> </span><span class="typ" style="word-wrap: break-word; color: rgb(137, 189, 255);">If</span><span class="pln" style="word-wrap: break-word;"> you experience problems </span><span class="kwd" style="word-wrap: break-word; color: rgb(226, 137, 100);">with</span></code></p></li>
<li><p><code style="word-wrap: break-word; background: none; text-shadow: rgb(0, 0, 0) 0px 1px 1px; color: rgb(184, 255, 184); line-height: 1.2em; padding-left: 10px !important; border-radius: 0px !important; margin-top: 1em !important; margin-bottom: 1em !important; border-width: initial !important; border-style: none !important; border-color: initial !important;"><span class="pln" style="word-wrap: break-word;">poor </span><span class="kwd" style="word-wrap: break-word; color: rgb(226, 137, 100);">time</span><span class="pln" style="word-wrap: break-word;"> synchronization</span><span class="pun" style="word-wrap: break-word;">,</span><span class="pln" style="word-wrap: break-word;"> you can increase the window </span><span class="kwd" style="word-wrap: break-word; color: rgb(226, 137, 100);">from</span><span class="pln" style="word-wrap: break-word;"> its </span><span class="kwd" style="word-wrap: break-word; color: rgb(226, 137, 100);">default</span></code></p></li>
<li><p><code style="word-wrap: break-word; background: none; text-shadow: rgb(0, 0, 0) 0px 1px 1px; color: rgb(184, 255, 184); line-height: 1.2em; padding-left: 10px !important; border-radius: 0px !important; margin-top: 1em !important; margin-bottom: 1em !important; border-width: initial !important; border-style: none !important; border-color: initial !important;"><span class="kwd" style="word-wrap: break-word; color: rgb(226, 137, 100);">size</span><span class="pln" style="word-wrap: break-word;"> of </span><span class="pun" style="word-wrap: break-word;">+-</span><span class="lit" style="word-wrap: break-word; color: rgb(51, 135, 204);">1min</span><span class="pln" style="word-wrap: break-word;"> </span><span class="pun" style="word-wrap: break-word;">(</span><span class="pln" style="word-wrap: break-word;">window </span><span class="kwd" style="word-wrap: break-word; color: rgb(226, 137, 100);">size</span><span class="pln" style="word-wrap: break-word;"> of </span><span class="lit" style="word-wrap: break-word; color: rgb(51, 135, 204);">3</span><span class="pun" style="word-wrap: break-word;">)</span><span class="pln" style="word-wrap: break-word;"> to about </span><span class="pun" style="word-wrap: break-word;">+-</span><span class="lit" style="word-wrap: break-word; color: rgb(51, 135, 204);">4min</span><span class="pln" style="word-wrap: break-word;"> </span><span class="pun" style="word-wrap: break-word;">(</span><span class="pln" style="word-wrap: break-word;">window </span><span class="kwd" style="word-wrap: break-word; color: rgb(226, 137, 100);">size</span><span class="pln" style="word-wrap: break-word;"> of</span></code></p></li>
<li><p><code style="word-wrap: break-word; background: none; text-shadow: rgb(0, 0, 0) 0px 1px 1px; color: rgb(184, 255, 184); line-height: 1.2em; padding-left: 10px !important; border-radius: 0px !important; margin-top: 1em !important; margin-bottom: 1em !important; border-width: initial !important; border-style: none !important; border-color: initial !important;"><span class="lit" style="word-wrap: break-word; color: rgb(51, 135, 204);">17</span><span class="pln" style="word-wrap: break-word;"> acceptable tokens</span><span class="pun" style="word-wrap: break-word;">).</span></code></p></li>
<li><p><code style="word-wrap: break-word; background: none; text-shadow: rgb(0, 0, 0) 0px 1px 1px; color: rgb(184, 255, 184); line-height: 1.2em; padding-left: 10px !important; border-radius: 0px !important; margin-top: 1em !important; margin-bottom: 1em !important; border-width: initial !important; border-style: none !important; border-color: initial !important;"></code></p></li>
<li><p><code style="word-wrap: break-word; background: none; text-shadow: rgb(0, 0, 0) 0px 1px 1px; color: rgb(184, 255, 184); line-height: 1.2em; padding-left: 10px !important; border-radius: 0px !important; margin-top: 1em !important; margin-bottom: 1em !important; border-width: initial !important; border-style: none !important; border-color: initial !important;"><span class="typ" style="word-wrap: break-word; color: rgb(137, 189, 255);">Do</span><span class="pln" style="word-wrap: break-word;"> you want to </span><span class="kwd" style="word-wrap: break-word; color: rgb(226, 137, 100);">do</span><span class="pln" style="word-wrap: break-word;"> so</span><span class="pun" style="word-wrap: break-word;">?</span><span class="pln" style="word-wrap: break-word;"> </span><span class="pun" style="word-wrap: break-word;">(</span><span class="pln" style="word-wrap: break-word;">y</span><span class="pun" style="word-wrap: break-word;">/</span><span class="pln" style="word-wrap: break-word;">n</span><span class="pun" style="word-wrap: break-word;">)</span><span class="pln" style="word-wrap: break-word;"> </span></code></p></li>
</ol>

意思是:默认情况下,密钥在 30 秒内有效,为了防止由于客户端与服务器时间偏移(时间相差太大)导致认证失败,google 身份验证器设计了时间容错措施。可以让你使用与当前时间偏移 1 到 4 分钟的密钥。

这个可根据实际情况进行配置,一般一分钟就足够了。

输入 y回车。

暴力破解防护

<ol class="linenums list-paddingleft-2" style="word-wrap: break-word; margin: 1em 2em; padding: 1px; border-left: 2px solid rgb(0, 153, 0); background-image: none; color: rgb(174, 174, 174); line-height: 1.2em; font-size: 9px;">
<li><p><code style="word-wrap: break-word; background: none; text-shadow: rgb(0, 0, 0) 0px 1px 1px; color: rgb(184, 255, 184); line-height: 1.2em; padding-left: 10px !important; border-radius: 0px !important; margin-top: 1em !important; margin-bottom: 1em !important; border-width: initial !important; border-style: none !important; border-color: initial !important;"><span class="typ" style="word-wrap: break-word; color: rgb(137, 189, 255);">If</span><span class="pln" style="word-wrap: break-word;"> the computer that you are logging into isn</span><span class="str" style="word-wrap: break-word; color: rgb(101, 176, 66);">'t hardened against brute-force</span></code></p></li>
<li><p><code style="word-wrap: break-word; background: none; text-shadow: rgb(0, 0, 0) 0px 1px 1px; color: rgb(184, 255, 184); line-height: 1.2em; padding-left: 10px !important; border-radius: 0px !important; margin-top: 1em !important; margin-bottom: 1em !important; border-width: initial !important; border-style: none !important; border-color: initial !important;"><span class="str" style="word-wrap: break-word; color: rgb(101, 176, 66);">login attempts, you can enable rate-limiting for the authentication module.</span></code></p></li>
<li><p><code style="word-wrap: break-word; background: none; text-shadow: rgb(0, 0, 0) 0px 1px 1px; color: rgb(184, 255, 184); line-height: 1.2em; padding-left: 10px !important; border-radius: 0px !important; margin-top: 1em !important; margin-bottom: 1em !important; border-width: initial !important; border-style: none !important; border-color: initial !important;"><span class="str" style="word-wrap: break-word; color: rgb(101, 176, 66);">By default, this limits attackers to no more than 3 login attempts every 30s.</span></code></p></li>
<li><p><code style="word-wrap: break-word; background: none; text-shadow: rgb(0, 0, 0) 0px 1px 1px; color: rgb(184, 255, 184); line-height: 1.2em; padding-left: 10px !important; border-radius: 0px !important; margin-top: 1em !important; margin-bottom: 1em !important; border-width: initial !important; border-style: none !important; border-color: initial !important;"></code></p></li>
<li><p><code style="word-wrap: break-word; background: none; text-shadow: rgb(0, 0, 0) 0px 1px 1px; color: rgb(184, 255, 184); line-height: 1.2em; padding-left: 10px !important; border-radius: 0px !important; margin-top: 1em !important; margin-bottom: 1em !important; border-width: initial !important; border-style: none !important; border-color: initial !important;"><span class="str" style="word-wrap: break-word; color: rgb(101, 176, 66);">Do you want to enable rate-limiting (y/n) </span></code></p></li>
</ol>

意思是:为了避免暴力破解,可以启用速率限制,默认情况下,每 30 秒只能尝试 3 次。

输入 y回车。

配置完成

配置完成后会在home目录下生成一个权限为 400 的隐藏文件,如下图所示:

SSH 安全加固篇:通过“运维密码”小程序实现 SSH 双因子认证

配置运维密码

打开微信小程序

打开微信,依次点击“发现”,“小程序”:

SSH 安全加固篇:通过“运维密码”小程序实现 SSH 双因子认证

输入“运维密码”并搜索:

SSH 安全加固篇:通过“运维密码”小程序实现 SSH 双因子认证

点击“运维密码”进入应用,然后点击右下角二维码图标:

SSH 安全加固篇:通过“运维密码”小程序实现 SSH 双因子认证

扫一扫配置 google-authenticator 时所生成的二维码,然后会识别出该场景信息,你可以根据需要修改场景信息,点击确定添加场景:

SSH 安全加固篇:通过“运维密码”小程序实现 SSH 双因子认证

添加完成:

SSH 安全加固篇:通过“运维密码”小程序实现 SSH 双因子认证

这样 Google 身份验证器就和“运维密码”匹配上了。下面我们要使 SSH 服务可以支持该验证。

配置 SSH 服务

添加认证模块

使用如下命令在 /etc/pam.d/sshd 文件添加认证模块:

<ol class="linenums list-paddingleft-2" style="word-wrap: break-word; margin: 1em 2em; padding: 1px; border-left: 2px solid rgb(0, 153, 0); background-image: none; color: rgb(174, 174, 174); line-height: 1.2em; font-size: 9px;"><li><p><code style="word-wrap: break-word; background: none; text-shadow: rgb(0, 0, 0) 0px 1px 1px; color: rgb(184, 255, 184); line-height: 1.2em; padding-left: 10px !important; border-radius: 0px !important; margin-top: 1em !important; margin-bottom: 1em !important; border-width: initial !important; border-style: none !important; border-color: initial !important;"><span class="kwd" style="word-wrap: break-word; color: rgb(226, 137, 100);">echo</span><span class="pln" style="word-wrap: break-word;"> </span><span class="str" style="word-wrap: break-word; color: rgb(101, 176, 66);">"auth required pam_google_authenticator.so"</span><span class="pln" style="word-wrap: break-word;"> </span><span class="pun" style="word-wrap: break-word;">>></span><span class="str" style="word-wrap: break-word; color: rgb(101, 176, 66);">/etc/</span><span class="pln" style="word-wrap: break-word;">pam</span><span class="pun" style="word-wrap: break-word;">.</span><span class="pln" style="word-wrap: break-word;">d</span><span class="pun" style="word-wrap: break-word;">/</span><span class="kwd" style="word-wrap: break-word; color: rgb(226, 137, 100);">sshd</span></code></p></li></ol>

配置挑战式密码认证:

<ol class="linenums list-paddingleft-2" style="word-wrap: break-word; margin: 1em 2em; padding: 1px; border-left: 2px solid rgb(0, 153, 0); background-image: none; color: rgb(174, 174, 174); line-height: 1.2em; font-size: 9px;"><li><p><code style="word-wrap: break-word; background: none; text-shadow: rgb(0, 0, 0) 0px 1px 1px; color: rgb(184, 255, 184); line-height: 1.2em; padding-left: 10px !important; border-radius: 0px !important; margin-top: 1em !important; margin-bottom: 1em !important; border-width: initial !important; border-style: none !important; border-color: initial !important;"><span class="kwd" style="word-wrap: break-word; color: rgb(226, 137, 100);">sed</span><span class="pln" style="word-wrap: break-word;"> </span><span class="pun" style="word-wrap: break-word;">-</span><span class="pln" style="word-wrap: break-word;">i </span><span class="str" style="word-wrap: break-word; color: rgb(101, 176, 66);">'s/ChallengeResponseAuthentication no/ChallengeResponseAuthentication yes/g'</span><span class="pln" style="word-wrap: break-word;"> </span><span class="pun" style="word-wrap: break-word;">/</span><span class="pln" style="word-wrap: break-word;">etc</span><span class="pun" style="word-wrap: break-word;">/</span><span class="kwd" style="word-wrap: break-word; color: rgb(226, 137, 100);">ssh</span><span class="pun" style="word-wrap: break-word;">/</span><span class="pln" style="word-wrap: break-word;">sshd_config</span></code></p></li></ol>

重启 sshd 服务:

<ol class="linenums list-paddingleft-2" style="word-wrap: break-word; margin: 1em 2em; padding: 1px; border-left: 2px solid rgb(0, 153, 0); background-image: none; color: rgb(174, 174, 174); line-height: 1.2em; font-size: 9px;"><li><p><code style="word-wrap: break-word; background: none; text-shadow: rgb(0, 0, 0) 0px 1px 1px; color: rgb(184, 255, 184); line-height: 1.2em; padding-left: 10px !important; border-radius: 0px !important; margin-top: 1em !important; margin-bottom: 1em !important; border-width: initial !important; border-style: none !important; border-color: initial !important;"><span class="kwd" style="word-wrap: break-word; color: rgb(226, 137, 100);">systemctl</span><span class="pln" style="word-wrap: break-word;"> restart </span><span class="kwd" style="word-wrap: break-word; color: rgb(226, 137, 100);">sshd</span><span class="pun" style="word-wrap: break-word;">.</span><span class="pln" style="word-wrap: break-word;">service</span></code></p></li></ol>

切记,如果你是远程登录到服务器上配置,切勿退出当前的 SSH 会话,而应该另外开一个会话去测试 SSH 登录。重启不会中断当前的 SSH 会话。

测试登录

以上配置完成基本上就搞定了,下面我们进行测试。

密码登录测试

另外开一个终端窗口进行连接,不要关闭当前的 SSH 连接。

输入命令登录主机:

<ol class="linenums list-paddingleft-2" style="word-wrap: break-word; margin: 1em 2em; padding: 1px; border-left: 2px solid rgb(0, 153, 0); background-image: none; color: rgb(174, 174, 174); line-height: 1.2em; font-size: 9px;"><li><p><code style="word-wrap: break-word; background: none; text-shadow: rgb(0, 0, 0) 0px 1px 1px; color: rgb(184, 255, 184); line-height: 1.2em; padding-left: 10px !important; border-radius: 0px !important; margin-top: 1em !important; margin-bottom: 1em !important; border-width: initial !important; border-style: none !important; border-color: initial !important;"><span class="kwd" style="word-wrap: break-word; color: rgb(226, 137, 100);">ssh</span><span class="pln" style="word-wrap: break-word;"> root@10</span><span class="pun" style="word-wrap: break-word;">.</span><span class="lit" style="word-wrap: break-word; color: rgb(51, 135, 204);">112.2</span><span class="pun" style="word-wrap: break-word;">.</span><span class="lit" style="word-wrap: break-word; color: rgb(51, 135, 204);">3</span></code></p></li></ol>

首先输入服务器的密码,接着会让输入“运维密码”生成的 6 位数字密钥。

SSH 安全加固篇:通过“运维密码”小程序实现 SSH 双因子认证

如下图:

SSH 安全加固篇:通过“运维密码”小程序实现 SSH 双因子认证

我们可以看到,在登录的时候,需要配合“运维密码”才能登录服务器。

公钥登录测试

如果使用公钥登录呢?以上配置是不是也是需要配合“运维密码”才能登录的,我们进行验证一下:

首先,我们将本机的公钥复制到远程机器的 authorized_keys 文件中。

<ol class="linenums list-paddingleft-2" style="word-wrap: break-word; margin: 1em 2em; padding: 1px; border-left: 2px solid rgb(0, 153, 0); background-image: none; color: rgb(174, 174, 174); line-height: 1.2em; font-size: 9px;"><li><p><code style="word-wrap: break-word; background: none; text-shadow: rgb(0, 0, 0) 0px 1px 1px; color: rgb(184, 255, 184); line-height: 1.2em; padding-left: 10px !important; border-radius: 0px !important; margin-top: 1em !important; margin-bottom: 1em !important; border-width: initial !important; border-style: none !important; border-color: initial !important;"><span class="kwd" style="word-wrap: break-word; color: rgb(226, 137, 100);">ssh</span><span class="pun" style="word-wrap: break-word;">-</span><span class="pln" style="word-wrap: break-word;">copy</span><span class="pun" style="word-wrap: break-word;">-</span><span class="kwd" style="word-wrap: break-word; color: rgb(226, 137, 100);">id</span><span class="pln" style="word-wrap: break-word;"> root@10</span><span class="pun" style="word-wrap: break-word;">.</span><span class="lit" style="word-wrap: break-word; color: rgb(51, 135, 204);">112.2</span><span class="pun" style="word-wrap: break-word;">.</span><span class="lit" style="word-wrap: break-word; color: rgb(51, 135, 204);">3</span></code></p></li></ol>

SSH 安全加固篇:通过“运维密码”小程序实现 SSH 双因子认证

登录测试:

SSH 安全加固篇:通过“运维密码”小程序实现 SSH 双因子认证

我们可以看到,不需要输入任何密码和一次性密钥,直接登录到了系统。

结合运维密码配置增强型SSH安全选项

针对上面公钥登录的测试,如果认为还不是很安全,我们可以设定如下登录场景:公钥 + 密码 + 运维密码,我们需要如何做呢?

配置 SSH 公钥双因子

修改 /etc/ssh/sshd_config 配置文件:

<ol class="linenums list-paddingleft-2" style="word-wrap: break-word; margin: 1em 2em; padding: 1px; border-left: 2px solid rgb(0, 153, 0); background-image: none; color: rgb(174, 174, 174); line-height: 1.2em; font-size: 9px;"><li><p><code style="word-wrap: break-word; background: none; text-shadow: rgb(0, 0, 0) 0px 1px 1px; color: rgb(184, 255, 184); line-height: 1.2em; padding-left: 10px !important; border-radius: 0px !important; margin-top: 1em !important; margin-bottom: 1em !important; border-width: initial !important; border-style: none !important; border-color: initial !important;"><span class="kwd" style="word-wrap: break-word; color: rgb(226, 137, 100);">echo</span><span class="pln" style="word-wrap: break-word;"> </span><span class="str" style="word-wrap: break-word; color: rgb(101, 176, 66);">"AuthenticationMethods publickey,keyboard-interactive:pam"</span><span class="pln" style="word-wrap: break-word;"> </span><span class="pun" style="word-wrap: break-word;">>></span><span class="str" style="word-wrap: break-word; color: rgb(101, 176, 66);">/etc/</span><span class="kwd" style="word-wrap: break-word; color: rgb(226, 137, 100);">ssh</span><span class="pun" style="word-wrap: break-word;">/</span><span class="pln" style="word-wrap: break-word;">sshd_config</span></code></p></li></ol>

重启 SSH 服务:

<ol class="linenums list-paddingleft-2" style="word-wrap: break-word; margin: 1em 2em; padding: 1px; border-left: 2px solid rgb(0, 153, 0); background-image: none; color: rgb(174, 174, 174); line-height: 1.2em; font-size: 9px;"><li><p><code style="word-wrap: break-word; background: none; text-shadow: rgb(0, 0, 0) 0px 1px 1px; color: rgb(184, 255, 184); line-height: 1.2em; padding-left: 10px !important; border-radius: 0px !important; margin-top: 1em !important; margin-bottom: 1em !important; border-width: initial !important; border-style: none !important; border-color: initial !important;"><span class="kwd" style="word-wrap: break-word; color: rgb(226, 137, 100);">systemctl</span><span class="pln" style="word-wrap: break-word;"> restart </span><span class="kwd" style="word-wrap: break-word; color: rgb(226, 137, 100);">sshd</span><span class="pun" style="word-wrap: break-word;">.</span><span class="pln" style="word-wrap: break-word;">service</span></code></p></li></ol>

登录测试(同样,请新开窗口):

<ol class="linenums list-paddingleft-2" style="word-wrap: break-word; margin: 1em 2em; padding: 1px; border-left: 2px solid rgb(0, 153, 0); background-image: none; color: rgb(174, 174, 174); line-height: 1.2em; font-size: 9px;"><li><p><code style="word-wrap: break-word; background: none; text-shadow: rgb(0, 0, 0) 0px 1px 1px; color: rgb(184, 255, 184); line-height: 1.2em; padding-left: 10px !important; border-radius: 0px !important; margin-top: 1em !important; margin-bottom: 1em !important; border-width: initial !important; border-style: none !important; border-color: initial !important;"><span class="kwd" style="word-wrap: break-word; color: rgb(226, 137, 100);">ssh</span><span class="pln" style="word-wrap: break-word;"> root@10</span><span class="pun" style="word-wrap: break-word;">.</span><span class="lit" style="word-wrap: break-word; color: rgb(51, 135, 204);">112.2</span><span class="pun" style="word-wrap: break-word;">.</span><span class="lit" style="word-wrap: break-word; color: rgb(51, 135, 204);">3</span></code></p></li></ol>

SSH 安全加固篇:通过“运维密码”小程序实现 SSH 双因子认证

可以看到,登录的时候是需要验证公钥、密码,及输入“运维密码”生成的密钥才能登录到系统。

没有密钥的情况下尝试登录测试,如下图:

SSH 安全加固篇:通过“运维密码”小程序实现 SSH 双因子认证

总结

 

至此,本文结束,更多的使用细节可以参照小程序内的帮助,或此文[7]

如有错误及不足欢迎指正。也欢迎大家加入到这个小程序的开发当中,乃至将这个小程序应用到你的应用场景中。

推荐文章

< 左右滑动查看相关文章 >

SSH 安全加固篇:通过“运维密码”小程序实现 SSH 双因子认证SSH 安全加固篇:通过“运维密码”小程序实现 SSH 双因子认证SSH 安全加固篇:通过“运维密码”小程序实现 SSH 双因子认证SSH 安全加固篇:通过“运维密码”小程序实现 SSH 双因子认证SSH 安全加固篇:通过“运维密码”小程序实现 SSH 双因子认证SSH 安全加固篇:通过“运维密码”小程序实现 SSH 双因子认证

输入文章 ID 或长按二维码直达


Hacking For Fun , 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:SSH 安全加固篇:通过“运维密码”小程序实现 SSH 双因子认证
喜欢 (0)
发表我的评论
取消评论
表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址