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

问题描述:

我正在尝试为亚马逊EC2 Ubuntu实例创建身份验证过程,该实例将要求使用Amazon生成的密钥对,并使用Google-Authenticator。 Ergo我想用我的pem文件登录到实例,然后提示验证码提示。如何创建一个pem文件+ google-authenticator访问Amazon EC2?

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 

如果我添加publickeyAuthenticationMethods然后在登录时提示我输入密码,而不是使用PEM我提供的文件:

ssh -i my-key.pem [email protected]*.*.*.* 

我如何获得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 

如上述CONFIGS的其余部分。注意publickey出现在keyboard-interactive之前AuthenticationMethods,否则验证码先出现然后pem文件检查。