如何创建一个 pem 文件 + google-authenticator 访问 Amazon EC2?

How can I create a pem file + google-authenticator access to Amazon EC2?

我正在尝试为 Amazon EC2 Ubuntu 实例创建身份验证过程,该过程需要使用 Amazon 生成的密钥对并使用 Google-Authenticator。因此,我想使用我的 pem 文件登录实例,然后使用验证码提示进行提示。

Verification code:

我已经成功地使用我的 pem 文件登录到我的服务器。我还成功地安装了 Google-Authenticator 并使用它使用我创建并提供特定密码的单独用户(不是 ubuntu)登录。

在我的 /etc/ssh/sshd_config 我有:

ChallengeResponseAuthentication yes
PasswordAuthentication no
UsePAM yes
AuthenticationMethods keyboard-interactive

在我的 /etc/pam.d/sshd 上:

@include common-auth
auth required pam_google_authenticator.so

如果我将 publickey 添加到 AuthenticationMethods,那么在登录时系统会提示我输入密码,而不是使用我提供的 pem 文件:

ssh -i my-key.pem ubuntu@*.*.*.*

如何让 OpenSSH 通过 pem 文件进行身份验证 --> google-authenticator?

谢谢!

我的解决方案是通过 pem 文件、密码和验证 OTP 进行检查。为此,我有:

在:/etc/pam.d/sshd/

@include common-auth
auth required pam_sepermit.so
auth required pam_google_authenticator.so

在:/etc/ssh/sshd_config/

AuthenticationMethods publickey,keyboard-interactive

其余配置如上所述。注意AuthenticationMethodspublickeykeyboard-interactive之前,否则先验证码,再检查pem文件。