AWS OpsWorks SSH 权限被拒绝 (publickey)

3
为了在 AWS OpsWorks 上部署 Rails 应用程序的实例,我必须为该实例定义一个 SSH 密钥。我按照帮助页面提供的步骤进行操作:http://docs.aws.amazon.com/opsworks/latest/userguide/workinginstances-ssh.html#workinginstances-ssh-third 1. 创建了密钥对并下载了 .pem 文件:AWSRails.pem。 2. 更改了文件的 chmod 为 600。 3. 在堆栈页面中,将默认 SSH 密钥添加到先前创建的密钥中(步骤 1)。 4. 在 Instance 页面中,获取公共 DNS 名称:ec2-54-72-154-78.eu-west-1.compute.amazonaws.com。 5. 在同一页面上,获取操作系统:Amazon Linux。 6. 在终端中,尝试建立与实例的 ssh 连接: ssh -v -i ~/Downloads/AWSRails.pem ec2-user@ec2-54-72-154-78.eu-west-1.compute.amazonaws.com。
我得到了以下输出:
OpenSSH_6.2p2, OSSLShim 0.9.8r 8 Dec 2011
debug1: Reading configuration data /etc/ssh_config
debug1: /etc/ssh_config line 20: Applying options for *
debug1: /etc/ssh_config line 102: Applying options for *
debug1: Connecting to ec2-54-72-154-78.eu-west-1.compute.amazonaws.com [54.72.154.78] port 22.
debug1: Connection established.
debug1: identity file AWSRails.pem type -1
debug1: identity file AWSRails.pem-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_6.2
debug1: Remote protocol version 2.0, remote software version OpenSSH_6.2
debug1: match: OpenSSH_6.2 pat OpenSSH*
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-ctr hmac-md5-etm@openssh.com none
debug1: kex: client->server aes128-ctr hmac-md5-etm@openssh.com none
debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(1024<1024<8192) sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_GROUP
debug1: SSH2_MSG_KEX_DH_GEX_INIT sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_REPLY
debug1: Server host key: RSA f0:52:63:a5:cf:d9:62:bc:f7:b9:f9:04:a7:05:93:5e
debug1: Host 'ec2-54-72-154-78.eu-west-1.compute.amazonaws.com' is known and matches the RSA host key.
debug1: Found key in /Users/Hassen/.ssh/known_hosts:12
debug1: ssh_rsa_verify: signature correct
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: Roaming not allowed by server
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Offering RSA public key: /Users/Hassen/.ssh/id_rsa
debug1: Authentications that can continue: publickey
debug1: Trying private key: AWSRails.pem
debug1: read PEM private key done: type RSA
debug1: Authentications that can continue: publickey
debug1: No more authentication methods to try.
Permission denied (publickey).

阅读调试消息,连接已建立,一切都正常,直到公钥身份验证方法。 我尝试了在StackOverflow上找到的许多相同问题,但都没有解决。

您有任何想法吗?谢谢。


1
你确定你没有使用Ubuntu创建实例吗?该实例是否在Amazon控制面板中显示其密钥为AWSRails.pem? - ffflabs
你在第二点上是正确的。我必须关闭实例并添加pem密钥...现在,我无法重新启动实例(在设置阶段失败),并且在从github部署时仍然出现publickey错误:Permission denied (publickey)。但是我可以通过SSH访问远程AWS实例。 - Hassen
1
同意第一条评论。您确定使用了亚马逊 Linux 实例类型吗?Ubuntu 实例有不同的默认用户。 - Paul Frederiksen
2个回答

0

值得检查用户名是否符合您的预期。我曾经遇到过完全相同的错误,原因是我使用的是Ubuntu实例而不是Amazon Linux,但这可能不是有不同用户名的唯一原因。

Opsworks控制台的SSH登录页面建议将user@example.com作为登录名的AWS/IAM用户使用userexamplecom作为SSH用户名。但对于Ubuntu,它是ubuntu,对于Amazon Linux或Red Hat,它是ec2-user,对于Debian,它是admin更多细节在此处(我个人没有使用所有这些)。

来自链接文章的一个好提示是尝试:

$ ssh root@hostname

由于某些系统会响应类似以下内容:

Please login as the user "ubuntu" rather than the user "root".

0

两种潜在的解决方案:

  1. 您的用户是否已打开SSH?检查您的权限(从控制台记得)。 如果只有您在堆栈上,则可能已经具有权限,但我知道当添加成员到我的开发团队时,我必须确保打开它。有关更多详细信息,请参见AWS OpsWorks页面上的SSH

  2. 我所有的“ssh到OpsWorks实例”的脚本在尝试SSH之前始终执行 ssh add-key ec2-keypair.pem 。 我相信这是在初始堆栈创建期间向您提供的密钥???还是什么?无论如何,如果您拥有该密钥,请尝试使用 ssh add-key 。 这也可能取决于您如何设置OpsWorks(个人密钥还是一个默认密钥)......


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接