Amazon ec2 运行ssh时出现权限被拒绝错误

Amazon ec2 运行ssh时出现权限被拒绝错误,amazon-ec2,superuser,Amazon Ec2,Superuser,我正试图从centos 7机器上ssh到我的ec2实例。我已将.pem文件添加到.ssh文件夹中 我错过什么了吗 [root@localhost .ssh]# cd /home/###/.ssh/ [root@localhost .ssh]# ls ##.pem root@localhost .ssh]# ssh centos@10.100.140.52 -vvv debug1: Trying private key: /root/.ssh/id_rsa debug3: no such i

我正试图从centos 7机器上ssh到我的ec2实例。我已将.pem文件添加到.ssh文件夹中

我错过什么了吗

[root@localhost .ssh]# cd /home/###/.ssh/
[root@localhost .ssh]# ls
##.pem

root@localhost .ssh]# ssh centos@10.100.140.52 -vvv


debug1: Trying private key: /root/.ssh/id_rsa
debug3: no such identity: /root/.ssh/id_rsa: No such file or directory
debug1: Trying private key: /root/.ssh/id_dsa
debug3: no such identity: /root/.ssh/id_dsa: No such file or directory
debug1: Trying private key: /root/.ssh/id_ecdsa
debug3: no such identity: /root/.ssh/id_ecdsa: No such file or directory
debug1: Trying private key: /root/.ssh/id_ed25519
debug3: no such identity: /root/.ssh/id_ed25519: No such file or directory
debug2: we did not send a packet, disable method
debug1: No more authentication methods to try.
Permission denied (publickey,gssapi-keyex,gssapi-with-mic).

您是root用户—在同一目录中是否有pem文件并不重要,在您的情况下,它将在默认目录/root/.ssh中查找。如果要使用该pem文件,请使用-i命令行选项:

ssh -i something.pem centos@10.100.140.52 -vvv

我看到您使用的是根shell,但您的问题表明密钥凭据存储在用户的主目录中。这是否作为该用户工作,即

[root@localhost .ssh]# su - ###
[###@localhost ~]$ ssh centos@10.100.140.52 -vvv
您还可以尝试覆盖ssh客户端查找.ssh文件的位置,尽管ssh会对不匹配的文件权限进行挑剔,例如

[root@localhost ~]# ssh -i ~###/.ssh/something.pem centos@10.100.140.52 -vvv
您可以将连接配置文件存储在~/.ssh/config中,即

Host ec2
  HostName 10.100.140.52
  IdentityFile ~/.ssh/identity_file
您是否尝试运行sudo-then命令?请参阅,特别是确保正确地对相关文件进行了CHMOD