如何在 Fedora Linux 中启用 SSH 的双因素身份验证如何在 Fedora Linux 中启用 SSH 的双因素身份验证如何在 Fedora Linux 中启用 SSH 的双因素身份验证如何在 Fedora Linux 中启用 SSH 的双因素身份验证
  • 文章
  • 正则表达式
    • 工具
  • 登录
找到的结果: {phrase} (显示: {results_count} 共: {results_count_total})
显示: {results_count} 共: {results_count_total}

加载更多搜索结果...

搜索范围
模糊匹配
搜索标题
搜索内容
发表 admin at 2025年2月28日
类别
  • 未分类
标签

如何在 Fedora Linux 中启用 SSH 的双因素身份验证

在信息技术领域,安全是当今的一个主要问题。每天都会针对组织发起新的复杂攻击。系统管理员使用不同的方法来强化服务器的安全性。与服务器交互的常见方法之一是使用 SSH(或 Secure SHell)协议,该协议广泛用于远程登录服务器。除了远程 shell 登录之外,它还用于在两台计算机之间复制文件。与 telnet、rcp、ftp 等其他方法不同,SSH 协议使用加密机制来保护两个主机之间的通信。

通过使用双因素身份验证可以进一步增强 SSH 协议提供的安全性。这将进一步在您的主机和攻击者之间筑起一道坚固的墙。要使用 SSH 连接到远程服务器,您将需要移动设备上运行的身份验证器应用程序提供的密码和验证码(或 OTP)。如果攻击者窃取了您的密码,这确实很有帮助,如果没有验证码,他将无法登录您的服务器。

有许多身份验证器应用程序可用于运行 Android 或 Apple IOS 的移动设备。本指南在 Fedora 服务器和移动设备上使用了 Google Authenticator 应用程序。

我们将涵盖的内容

本指南将介绍如何使用 SSH 协议的双因素身份验证来防止未经授权访问我们的 Fedora 30 工作站。我们将尝试从 Xubuntu 客户端计算机登录到 Fedora 服务器,看看设置是否按预期工作。让我们开始使用双因素身份验证配置 SSH。

先决条件

  1. 使用“sudo”用户帐户安装在远程服务器上的 Fedora 30 操作系统。

  2. 用于访问上述服务器的 Xubuntu 机器。

  3. 安装了 Google 身份验证器应用程序的移动设备。

设置概述

  1. Fedora 30 机器 IP:192.168.43.92

  2. Xubuntu机器IP:192.168.43.71

  3. 带有 Google 身份验证器应用程序的移动设备。

步骤 1. 使用以下命令在 Fedora 30 服务器上安装 Google-Authenticator:

$ sudo dnf install -y google-authenticator

步骤 2. 运行以下命令在您的服务器上启动 Google 身份验证器:

$ google-authenticator

它将询问一些问题来配置服务器以与您的移动设备配合使用:

Do you want authentication tokens to be time-based (y/n) y [Enter' Y' here]

它将在终端窗口上显示一个二维码;暂时保持此终端窗口打开。

第 3 步。在您的移动设备上安装 Google 身份验证器应用并打开它。现在单击“扫描 QR 码”选项。现在将移动摄像头聚焦于扫描服务器终端窗口上的 QR 码。

步骤4.扫描二维码后,您的移动设备将为您的服务器添加一个帐户,并生成一个随机代码,该随机代码会随着计时器的轮转而不断变化,如下图所示:

第 5 步。现在返回服务器终端窗口,并在此处输入移动设备上的验证码。一旦代码被确认,就会生成一组暂存代码。如果您丢失移动设备,这些刮刮码可用于登录您的服务器。因此,请将它们保存在安全的地方。

第6步。在接下来的步骤中,它将询问一些问题以完成配置。我们在下面给出了配置设置的一组问题及其答案。您可以根据需要更改这些答案:

Do you want me to update your "/home/linux/.google_authenticator" file? (y/n) y   [Enter ‘y’ here]

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   [Enter 'y’ here]

By default, a new token is generated every 30 seconds by the mobile app.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 the 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   [Enter ‘y’ here]

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   [Enter ‘y’ here]

第 7 步。 现在使用任何编辑器打开 sshd_config 文件

$ sudo vi /etc/ssh/sshd_config

并执行以下步骤:

  1. 取消注释并将PasswordAuthentication设置为yes。

  2. 取消注释并将ChallengeResponseAuthentication 设置为yes。

  3. 取消注释并将 UsePAM 设置为 yes。

保存并关闭文件。

第 8 步。 接下来,打开 /etc/pam.d/sshd 文件

$ sudo vi /etc/pam.d/sshd

并在“auth substack password auth”行下方添加以下行:

auth required pam_google_authenticator.so

步骤 9. 使用以下命令在 Fedora 服务器上启动并启用 SSH 服务:

$ sudo systemctl start sshd
$ sudo systemctl enable sshd

配置服务器的所有步骤现已完成。我们现在将转移到我们的客户端计算机,即本例中的 Xubuntu。

第 10 步。 现在尝试使用 SSH 从 Xubuntu 计算机登录到 Fedora 30 服务器:

$ ssh linux@192.168.43.92

正如您所看到的,SSH 首先要求服务器的密码,然后要求您的移动设备提供验证码。正确输入验证码后,即可登录远程Fedora服务器。

结论

恭喜,我们已经在 Fedora 30 操作系统上成功配置了具有双因素身份验证的 SSH 访问。您可以进一步配置SSH仅使用验证码登录,无需远程服务器密码。

©2015-2025 艾丽卡 support@alaica.com