带有 SSH 2FA 的 Ubuntu 18 服务器

带有 SSH 2FA 的 Ubuntu 18 服务器

我想在我的 Ubuntu 18.04 LTS 服务器上通过 SSH 设置 2FA。我不想使用 Google Authenticator,而是想使用开源解决方案。

除了 Google Authenticator 之外,有没有关于使用其他免费产品的指南?

先感谢您。

问候,

答案1

这些指南应该与其他 2FA 应用程序兼容(例如免費 OTP) 也是如此。

Google Authenticator 使用拓扑拓扑图以及大多数 2FA 应用程序,例如开源免費 OTP使用相同的标准,您可以用它们代替 Google Authenticator。

为了完整起见,以下是来自数字海洋设置 FreeOTP。请注意,SSH 公钥登录不会要求 2FA 令牌,如果您想使用 2FA 进行公钥身份验证,请参阅数字海洋的指南(并禁用基于密码的身份验证)。

  • 更新 Ubuntu 的存储库并安装libpam-google-authenticator(这也适用于其他 2FA 应用程序)。

    sudo apt update && sudo apt install libpam-google-authenticator
    
  • 为您的用户设置 TOTP 密钥:

    google-authenticator
    

    Do you want authentication tokens to be time-basedDo you want me to update your "~/.google_authenticator" file问题回答是。

  • 使用以下方式扫描(大)二维码(大多数 GUI 终端仿真器都允许使用Ctrl+-缩小,使用Ctrl+0重置缩放)免費 OTP或您选择的 2FA 应用程序。

  • 将备份代码写在某处并安全存储。

  • 配置以允许 2FA 登录。如果您不想允许未设置 2FA 的用户登录,openssh-server可以删除。nullok

    [ -e /etc/pam.d/sshd ] || echo '@include common-auth' | sudo tee /etc/pam.d/sshd
    echo auth 'required pam_google_authenticator.so nullok' | sudo tee -a /etc/pam.d/sshd
    sudo nano /etc/ssh/sshd_config
    
  • 找到该ChallengeResponseAuthentication行并将其更改为ChallengeResponseAuthentication yes,然后按Ctrl+保存文件O并按+关闭。EnterCtrlXnano

  • 重新启动sshd以应用更改。

    sudo systemctl restart sshd
    
  • 打开另一个终端(如果它不起作用,您仍然可以访问)并尝试登录。

相关内容