我使用 Amazon 64 位 Linux (amzn-ami-2011.09.1.x86_64-ebs (ami-20506254)) 在 AWS 上启动了一个新的 EC2 实例,但无法通过 ssh 连接该实例。我使用 生成了一个公钥/私钥 ssh 密钥对,ssh-keygen -t rsa
并将 .pub (公钥) 密钥添加到 EC2 管理控制台中的密钥对中。
当我尝试运行时:ssh -i ~/.ssh/aws_ec2 -v ec2-46-137-17-221.eu-west-1.compute.amazonaws.com
我得到以下输出:
OpenSSH_5.2p1, OpenSSL 0.9.8r 8 Feb 2011
debug1: Reading configuration data /Users/casey/.ssh/config
debug1: Reading configuration data /etc/ssh_config
debug1: Connecting to ec2-79-125-85-42.eu-west-1.compute.amazonaws.com [79.125.85.42] port 22.
debug1: Connection established.
debug1: identity file /Users/casey/.ssh/aws_ec2 type 1
debug1: identity file /Users/casey/.ssh/id_rsa type 1
debug1: Remote protocol version 2.0, remote software version OpenSSH_5.3
debug1: match: OpenSSH_5.3 pat OpenSSH*
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_5.2
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-ctr hmac-md5 none
debug1: kex: client->server aes128-ctr hmac-md5 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: Host 'ec2-79-125-85-42.eu-west-1.compute.amazonaws.com' is known and matches the RSA host key.
debug1: Found key in /Users/casey/.ssh/known_hosts:8
debug1: ssh_rsa_verify: signature correct
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
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 public key: /Users/casey/.ssh/id_rsa
debug1: Authentications that can continue: publickey
debug1: Offering public key: /Users/casey/.ssh/aws_ec2
debug1: Authentications that can continue: publickey
debug1: No more authentication methods to try.
Permission denied (publickey).
不确定发生了什么,因为它确实提供了我的 ssh 私钥,但似乎被拒绝了。有人知道发生了什么吗?
答案1
答案2
chmod 700 /Users/casey/.ssh
chmod 600 /Users/casey/.ssh/*
确保您使用正确的用户名登录。aws 提供的默认 ssh 用户是
ec2-user : RHEL/centos, etc..
ubuntu: Ubuntu
另外,尝试指定如下所示的特定密钥文件。
ssh -i /Users/casey/.ssh/privatekey [email protected]