带密码的 ssh,回退到 Google Authenticator

WoJ*_*WoJ 8 ssh google-authenticator

随着Google Authenticator的引入以及将其与 ssh一起使用的能力,我想知道是否有人已经通过 sshd_config 设置

  • 首先期待一把钥匙
  • 如果失败,请回退到使用 Google Authenticator 进行身份验证

这个想法通常与密钥无缝连接,并且通常在不太友好的环境中与两个因素机制连接。

Wil*_*son 16

是的,我有一个设置,我可以ssh使用公钥身份验证到我的服务器,当我的私钥不可用时,回退到使用 Google 身份验证器 + 密码的两因素身份验证。这些是您可以用来设置它的步骤。

安装 Google 身份验证器

我的服务器正在运行 Ubuntu Bionic Beaver (18.04.1)。您可以使用apt以下方法安装 Google 身份验证器:

$ sudo apt install libpam-google-authenticator
Run Code Online (Sandbox Code Playgroud)

配置sshd

打开/etc/pam.d/sshd并在顶部添加以下行:

auth optional pam_google_authenticator.so
Run Code Online (Sandbox Code Playgroud)

打开/etc/ssh/sshd_config并更改一行。现有线路是

ChallengeResponseAuthentication no
Run Code Online (Sandbox Code Playgroud)

你应该把它改成

ChallengeResponseAuthentication yes
Run Code Online (Sandbox Code Playgroud)

为您的帐户配置 Google 身份验证器

下一步是为您的帐户启用 Google 身份验证器。您只需运行以下命令即可:

$ google-authenticator
Run Code Online (Sandbox Code Playgroud)

确保您以将要建立 ssh 连接的用户而不是root用户身份运行它。记下您的新密钥和紧急刮刮码。该向导将询问您几个问题来为您的帐户配置安全设置。

配置您的移动应用程序

我使用适用于 iPhone 的 Google 身份验证器应用程序。这个应用程序有一个 [+] 按钮,允许我使用我从google-authenticator服务器上的命令获得的密钥添加一个新的基于时间的令牌。设置起来很简单。我无法帮助您处理任何其他平台上的应用程序,但我想这个过程同样简单。

扣动扳机

您需要做的最后一件事是重新启动sshd

$ sudo /etc/init.d/ssh restart
Run Code Online (Sandbox Code Playgroud)

此时,当您在私钥可用的情况下尝试连接到服务器时,身份验证就起作用了。当您的私钥不可用时,您将收到输入验证码的提示,然后是您的帐户密码。

宾果游戏,两因素身份验证。