从另一个远程服务器通过 SSH 连接到 AWS ec2 实例?

SSH into AWS ec2 instance from another remote server?

我正在尝试从 Digital Ocean 上的远程服务器上的用户通过 ssh 连接到 AWS ec2 实例。

我将私钥上传到 Digital Ocean 用户的 .ssh 文件夹中,在 .ssh 目录中创建了一个配置文件以指向身份文件(.pem 文件包含私有key) 然后通过 ssh-keygen -y 生成一个 public 密钥,并将其添加到 ec2 实例上用户的 '.ssh/authorized_keys' 文件中。

我的本地计算机以这种方式毫无问题地连接到 ec2 实例,我假设我可以以类似的方式在远程 Digital Ocean 实例上设置用户,但是当我收到 Permission denied (publickey). 错误时尝试连接。

详细错误输出:

debug1: Found key in /home/temp_user/.ssh/known_hosts:2
debug1: rekey after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: rekey after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS received
debug1: SSH2_MSG_EXT_INFO received
debug1: kex_input_ext_info: server-sig-algs=<rsa-sha2-256,rsa-sha2-512>
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Trying private key: .ssh/digital-ocean.pem
debug1: Authentications that can continue: publickey
debug1: No more authentication methods to try.

temp_user 是 Digital Ocean 服务器上的新用户。 digital-ocean.pem 是在 AWS 控制台中创建的私钥,public 密钥是从该控制台为 aws 实例上的新用户生成并存储在 .ssh/authorized_keys 中的。

为了测试,我临时上传了我在本地使用的私钥和

ssh -i .ssh/local.pem <user>@<instance id> 有效。

我觉得这可能与 aws 实例上新创建的用户有关。

我该如何排查或解决这个问题?

.ssh 目录应具有 755 权限并归用户所有。 authorized_keys 文件应具有 644 权限并归用户所有。