为了在AWS OpsWorks上部署Rails应用程序的实例,我必须为该实例定义SSH密钥。我按照帮助页面中提供的步骤操作:http://docs.aws.amazon.com/opsworks/latest/userguide/workinginstances-ssh.html#workinginstances-ssh-third
.pem
文件:AWSRails.pem chmod
更改为600 在终端中,我尝试与实例建立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).
读取调试消息,建立连接并且一切正常,直到publickey认证方法。我尝试了很多在StackOverflow上发现的相同问题,但都没有用。
你知道吗?感谢。答案 0 :(得分:0)
两种可能的解决方案:
您是否已为用户启用了SSH?检查您的权限(从仪表板IIRC)。如果它只是你在堆栈上,那么你可能已经拥有权限,但我知道我必须确保在向我的开发团队添加成员时转向它。 For more details see the AWS OpsWorks page on SSH
在实际尝试SSH之前,我所有的“ssh进入OpsWorks实例”脚本总是ssh add-key ec2-keypair.pem
。我相信这是在初始堆栈创建过程中给你的关键???或者其他的东西?无论如何,如果你有这个密钥,请尝试ssh add-key
。这可能还取决于您如何设置OpsWorks(个人密钥与一个默认密钥)...
答案 1 :(得分:0)
It’s worth checking if the username is what you expect it to be. I had exactly the same error, and it was because I was using Ubuntu instances rather than Amazon Linux, but this may not be the only reason for having a different username.
The Opsworks console’s SSH login page suggests userexamplecom
as the SSH username for an AWS/IAM user with user@example.com
as a login. But for Ubuntu it’s ubuntu
, Amazon Linux or Red Hat it’s ec2-user
, and Debian it’s admin
. More details here (I haven’t used all of these personally).
A good tip from the linked article is to try:
$ ssh root@hostname
As some systems will respond with something like:
Please login as the user "ubuntu" rather than the user "root".