使用 .pem 文件通过 ssh 连接到亚马逊实例权限被拒绝(公钥)

使用 .pem 文件通过 ssh 连接到亚马逊实例权限被拒绝(公钥)

我正在尝试使用我的“.pem”文件登录亚马逊上的实例,该文件具有 600 个权限:

ssh -v -i FTPServer.pem [email protected]

我尝试了所有可能的用户“root/ubuntu/ec2-user..”我总是收到以下内容:

    OpenSSH_6.6.1, OpenSSL 1.0.1f 6 Jan 2014
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug1: Connecting to ec2-xx-xxx-xxx-xxx.compute-1.amazonaws.com [xx.xxx.xxx.xxx] port 22.
debug1: Connection established.
debug1: identity file FTPServer.pem type -1
debug1: identity file FTPServer.pem-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_6.6.1p1 Ubuntu-8
debug1: Remote protocol version 2.0, remote software version OpenSSH_5.1p1 Debian-6ubuntu2
debug1: match: OpenSSH_5.1p1 Debian-6ubuntu2 pat OpenSSH_5* compat 0x0c000000
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<3072<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 0f:ad:a5:01:e1:75:82:fa:54:bd:56:53:34:d9:7e:6b
debug1: Host 'ec2-xx-xxx-xxx-xxx.compute-1.amazonaws.com' is known and matches the RSA host key.
debug1: Found key in /home/myhome/.ssh/known_hosts:6
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: Downloads/FTPServer.pem
debug1: Authentications that can continue: publickey
debug1: Trying private key: FTPServer.pem
debug1: key_parse_private2: missing begin marker
debug1: read PEM private key done: type RSA
debug1: Authentications that can continue: publickey
debug1: No more authentication methods to try.
Permission denied (publickey).

答案1

除非您在创建时提供了自定义用户列表,否则默认的“ubuntu”用户应该仍然存在,并且 EC2 密钥被放在该用户上,就像典型配置那样。

为了使其对其他用户起作用,您需要从中取出行/home/ubuntu/.ssh/authorized_keys并将它们放入文件中/home/$USER/.ssh/authorized_keys$USER您专门尝试使用该密钥工作的用户名在哪里)。

但是,根据您的评论,这不是您的 EC2 实例,您只是收到了 ,但.pem没有实际的登录说明。您需要联系管理员(设置 EC2 实例的人)并请求登录说明,并指示他们验证 的公钥是否在他们希望您以该身份登录的用户的主目录中的文件.pem中可用。.ssh/authorized_keys

答案2

这个问题是因为我正在使用错误的 .pem 文件然后我以默认用户“ubuntu”的身份成功连接到亚马逊实例。

相关内容