如何使用双因素身份验证保护 SSH

金钱(警告)

** 状态:** 被贬值

此文章已被删除,不再保留。

理由

本文重复了更新的、更准确的内容。

相反,看

本文可能仍然有用作为参考,但可能无法工作或遵循最佳实践。

请参阅如何在 Ubuntu 16.04 上为 SSH 设置多因素身份验证(https://andsky.com/tech/tutorials/how-to-set-up-multi-factor-authentication-for-ssh-on-ubuntu-16-04)。

美元

介绍

要通过双重身份验证来保护您的 SSH 服务器,您可以使用 Google Authenticator PAM 模块。

每次你连接,你必须从你的智能手机输入代码。

** 注意:** 如果您为正常用户启用 Google 身份验证器,但不为 root,您将不再可以直接登录 root 用户,您将需要先登录为新用户,然后通过 su 命令切换到超级用户以获取 root。

在您在 VPS 上做任何事情之前,请安装 Google Authenticator 应用程序,它适用于 Android、iOS 和 BlackBerry. 使用市场安装应用程序或使用移动浏览器访问 m.google.com/authenticator. 然后连接到您的 VPS 并切换到 root 用户。

步骤一 - 安装依赖性

1sudo apt-get install libpam-google-authenticator

libqrencode3 将自动安装,并允许您使用手机的相机直接从控制台扫描 qr 代码。

第二步 - 编辑配置文件

要使用该模块,您需要编辑两个配置文件。

1nano /etc/pam.d/sshd

在文件的顶部添加下列行:

1auth required pam_google_authenticator.so

还有一个文件可以编辑:

1nano /etc/ssh/sshd_config

查找并更改下列行:

1ChallengeResponseAuthentication yes

步骤三:为用户启用两因素身份验证

您可以为 root 用户或任何其他用户激活 Google 身份验证器. 切换到应该使用两因素身份验证的用户,然后键入:

1google-authenticator

您将被要求回答几个问题;回答前两个问题是(y):

1Do you want authentication tokens to be time-based (y/n) y
1Do you want me to update your "/home/USERNAME/.google_authenticator" file (y/n) y

您可以根据您的需求回答下列问题。

您可以使用 Google Authenticator 应用程序扫描 qr 代码,或使用秘密密密钥和验证代码添加帐户。

现在重新切换到 root 并重新启动 SSH 服务器. 如果您为 root 用户添加了双重身份验证,您可以跳过下一步。

1su root

最后,重新启动SSH服务器。

1/etc/init.d/ssh restart

你现在应该有一个SSH服务器,具有双重身份验证!

Published At
Categories with 技术
comments powered by Disqus