Amazon web services AWS OpsWorks SSH权限被拒绝(公钥)

Amazon web services AWS OpsWorks SSH权限被拒绝(公钥),amazon-web-services,ssh,amazon-ec2,Amazon Web Services,Ssh,Amazon Ec2,为了在AWS OpsWorks上部署Rails应用程序的实例,我必须为该实例定义一个SSH密钥。我遵循了帮助页面中提供的步骤: 我创建了密钥对并下载了.pem文件:AWSRails.pem 我已将文件的chmod更改为600 在堆栈页面中,我将默认SSH密钥添加到先前创建的密钥中(步骤1) 在实例页面中,我得到了公共DNS名称:ec2-54-72-154-78.eu-west-1.compute.amazonaws.com 在同一页中,我看到了操作系统:Amazon Linux 在终端中,我尝试

为了在AWS OpsWorks上部署Rails应用程序的实例,我必须为该实例定义一个SSH密钥。我遵循了帮助页面中提供的步骤:

  • 我创建了密钥对并下载了
    .pem
    文件:AWSRails.pem
  • 我已将文件的
    chmod
    更改为600
  • 在堆栈页面中,我将默认SSH密钥添加到先前创建的密钥中(步骤1)
  • 在实例页面中,我得到了公共DNS名称:ec2-54-72-154-78.eu-west-1.compute.amazonaws.com
  • 在同一页中,我看到了操作系统:Amazon Linux
  • 在终端中,我尝试建立到实例的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).
    
    OpenSSH_6.2p2,OSSLShim 0.9.8r 2011年12月8日
    debug1:读取配置数据/etc/ssh\u config
    debug1:/etc/ssh\u配置第20行:应用*
    debug1:/etc/ssh\u配置行102:应用*
    debug1:连接到ec2-54-72-154-78.eu-west-1.compute.amazonaws.com[54.72.154.78]端口22。
    debug1:已建立连接。
    debug1:标识文件AWSRails.pem类型-1
    debug1:标识文件AWSRails.pem-cert类型-1
    debug1:启用协议2.0的兼容模式
    debug1:本地版本字符串SSH-2.0-OpenSSH_6.2
    debug1:远程协议版本2.0,远程软件版本OpenSSH_6.2
    debug1:match:OpenSSH_6.2 pat OpenSSH*
    debug1:SSH2\u MSG\u KEXINIT已发送
    debug1:SSH2\u MSG\u KEXINIT已收到
    debug1:kex:server->client aes128 ctr hmac-md5-etm@openssh.com没有一个
    debug1:kex:客户端->服务器aes128 ctr hmac-md5-etm@openssh.com没有一个
    
    debug1:SSH2\u MSG\u KEX\u DH\u GEX\u请求(1024两种可能的解决方案:

  • 您是否为您的用户打开了SSH?检查您的权限(从仪表板IIRC)。如果堆栈上只有您,那么您可能已经拥有权限,但我知道在向我的开发团队添加成员时,我必须确保打开它

  • 我所有的“ssh到OpsWorks实例”脚本在实际尝试ssh之前都会执行
    ssh添加密钥ec2 keypair.pem
    。我相信这是在初始堆栈创建期间提供给您的密钥???或其他什么?无论如何,如果您有该密钥,请尝试
    ssh添加密钥
    。这也可能取决于您如何设置OpsWorks(个人钥匙与一个默认钥匙)


  • 值得检查用户名是否符合您的预期。我也有同样的错误,这是因为我使用的是Ubuntu实例而不是Amazon Linux,但这可能不是使用不同用户名的唯一原因

    Opsworks控制台的SSH登录页面建议使用
    userexamplecom
    作为AWS/IAM用户的SSH用户名user@example.com
    作为登录名。但对于Ubuntu,它是
    Ubuntu
    ,Amazon Linux或Red Hat是
    ec2用户
    ,Debian是
    管理员
    (我没有亲自使用所有这些)

    链接文章中的一个好提示是:

    $ ssh root@hostname
    
    因为有些系统会做出如下响应:

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

    你确定你没有用Ubuntu创建你的实例吗?该实例在amazon dashboard中是否显示为以AWSRails.pem作为其密钥?第二点你说得对。我必须关闭该实例并添加pem密钥…现在,我无法重新启动该实例(在安装阶段失败,)从github部署时仍然存在公钥错误:
    权限被拒绝(公钥)
    。但是我可以使用SSH访问远程AWS实例。同意第一条评论。您确定使用了amazon linux实例类型吗?ubuntu实例具有不同的默认用户。