运行 ssh 时权限被拒绝错误

Permission denied error while running ssh

我正在尝试从 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 中存储连接 "profiles",即

Host ec2
  HostName 10.100.140.52
  IdentityFile ~/.ssh/identity_file