为什么我无法通过 ssh 进入我的 aws ec2 实例?权限被拒绝(公钥)

为什么我无法通过 ssh 进入我的 aws ec2 实例?权限被拒绝(公钥)

我创建了两个 ec2 实例,并且能够顺利通过 ssh 连接到前两个实例。创建第三个实例后,我在尝试通过 ssh 连接到其中任何一个实例时收到此错误。

这就是我正在运行的: ssh -v -i /Users/name/meteor.pem [email protected].###

要得到:

 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 52.25.###.## [52.25.###.##] port 22.
debug1: Connection established.
debug1: identity file /Users/name/.ssh/meteor.pem type -1
debug1: identity file /Users/name/.ssh/meteor.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.6.1p1 Ubuntu-2ubuntu2
debug1: match: OpenSSH_6.6.1p1 Ubuntu-2ubuntu2 pat OpenSSH*
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-ctr [email protected] none
debug1: kex: client->server aes128-ctr [email protected] none
debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(1024<1024<##92) 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 3f:5a:e4:15:3e:c6:ee:f4:6e:97:59:02:ee:df:e2:a5
debug1: Host '52.25.###.##' is known and matches the RSA host key.
debug1: Found key in /Users/name/.ssh/known_hosts:13
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/name/.ssh/github_rsa
debug1: Authentications that can continue: publickey
debug1: Trying private key: /Users/name/.ssh/meteor.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).

我试过了这篇文章的建议:

sudo chmod 700 ~/.ssh/
sudo chmod 600 ~/.ssh/*
sudo chown -R User ~/.ssh/
sudo chgrp -R User ~/.ssh/

但是这条线 chgrp -R User ~/.ssh/给了我错误chgrp: mycomputerusername: illegal group name

我不知道组名应该是什么。我的 aws 账户用户名?

我也不知道我做了什么导致了这个错误。每次我创建一个新的 pem 时我都会运行chmod 600 meteor.pem,所以也许我输入了错误的这一行,导致权限问题?

对于下一步该尝试什么,任何建议都将不胜感激!

答案1

由于您使用 700 作为目录的权限,使用 600 作为 .ssh 中的文件的权限,因此无需更改组。

从上面的日志中,它显示使用meteor.pem,您在创建第 3 个 EC2 实例时是否使用了不同的密钥?

答案2

您可以使用 aws-cli 将您的私钥指纹与 ec2-fingerprint-key .ssh/key.pem(您的私钥/密钥名称的路径)进行比较,并与您的实例公共指纹进行比较

相关内容