linux - AWS SSH : Permission denied (publickey)

标签 linux amazon-web-services ssh amazon-ec2 server

<分区>

我正在尝试连接到 AWS 实例。我知道我肯定已经在我的桌面上下载了 key 对,但出于某种原因它无法识别它?我已经使用 chmod 400 更改了权限但仍然会发生以下情况:

martycep:~ martincepeda1$ ssh -v -i “privatekey.pem” ec2-user@ec2-xx-xx-xx-xx.us-east-2.compute.amazonaws.com Warning: Identity file privatekey.pem not accessible: No such file or directory. OpenSSH_6.9p1, LibreSSL 2.1.8 debug1: Reading configuration data /etc/ssh/ssh_config debug1: /etc/ssh/ssh_config line 21: Applying options for * debug1: Connecting to ec2-xx-xx-xxx-xx.us-east-2.compute.amazonaws.com [xx.xx.xxx.xx] port 22. debug1: Connection established. debug1: identity file /Users/martincepeda1/.ssh/id_rsa type 1 debug1: key_load_public: No such file or directory debug1: identity file /Users/martincepeda1/.ssh/id_rsa-cert type -1 debug1: key_load_public: No such file or directory debug1: identity file /Users/martincepeda1/.ssh/id_dsa type -1 debug1: key_load_public: No such file or directory debug1: identity file /Users/martincepeda1/.ssh/id_dsa-cert type -1 debug1: key_load_public: No such file or directory debug1: identity file /Users/martincepeda1/.ssh/id_ecdsa type -1 debug1: key_load_public: No such file or directory debug1: identity file /Users/martincepeda1/.ssh/id_ecdsa-cert type -1 debug1: key_load_public: No such file or directory debug1: identity file /Users/martincepeda1/.ssh/id_ed25519 type -1 debug1: key_load_public: No such file or directory debug1: identity file /Users/martincepeda1/.ssh/id_ed25519-cert type -1 debug1: Enabling compatibility mode for protocol 2.0 debug1: Local version string SSH-2.0-OpenSSH_6.9 debug1: Remote protocol version 2.0, remote software version OpenSSH_6.6.1 debug1: match: OpenSSH_6.6.1 pat OpenSSH_6.6.1* compat 0x04000000 debug1: Authenticating to ec2-xx-xx-xxx-xx.us-east-2.compute.amazonaws.com:22 as 'ec2-user' debug1: SSH2_MSG_KEXINIT sent debug1: SSH2_MSG_KEXINIT received debug1: kex: server->client chacha20-poly1305@openssh.com <implicit> none debug1: kex: client->server chacha20-poly1305@openssh.com <implicit> none debug1: expecting SSH2_MSG_KEX_ECDH_REPLY debug1: Server host key:xxxxxxxxxxxxxx debug1: Host 'ec2-xx-xx-xxx-xx.us-east-2.compute.amazonaws.com' is known and matches the ECDSA host key. debug1: Found key in /Users/martincepeda1/.ssh/known_hosts:6 debug1: SSH2_MSG_NEWKEYS sent debug1: expecting SSH2_MSG_NEWKEYS debug1: SSH2_MSG_NEWKEYS received 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/martincepeda1/.ssh/id_rsa debug1: Authentications that can continue: publickey debug1: Offering RSA public key: /Users/martincepeda1/.ssh/id_rsa debug1: Authentications that can continue: publickey debug1: Offering RSA public key: /Users/martincepeda1/.ssh/id_rsa debug1: Authentications that can continue: publickey debug1: Trying private key: /Users/martincepeda1/.ssh/id_dsa debug1: Trying private key: /Users/martincepeda1/.ssh/id_ecdsa debug1: Trying private key: /Users/martincepeda1/.ssh/id_ed25519 debug1: No more authentication methods to try. Permission denied (publickey). martycep:~ martincepeda1$

如有任何建议/想法,我们将不胜感激。谢谢。

最佳答案

Warning: Identity file privatekey.pem not accessible: No such file or directory

此输出表示您没有任何名为“privatekey.pem”的文件

也许您更改了关键权限,例如:

chmod 0400 **~/.ssh/privatekey.pem**

文件应该是这样的:

-r--------+ 1 user group     1671 Jun  5 11:37 privatekey.pem

在那种情况下你应该这样做:

ssh -i **~/.ssh/privatekey.pem** ec2-user@ec2-xx-xx-xx-xx.us-east-2.compute.amazonaws.com

检查你的 key 在哪里!

解决这个问题后,别忘了您必须在主机中添加公钥:ec2-user@ec2-xx-xx-xx-xx.us-east-2.compute.amazonaws.com

cat 'your_public_key' >>  ~/.ssh/authorized_keys

否则您的私钥将与服务器中的公钥不匹配。

关于linux - AWS SSH : Permission denied (publickey),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44419828/

相关文章:

如果 max(id) - min(id) > 50,000,则 mysql 删除较早的数据

linux - Github - 旧帐户的权限被拒绝

linux - 重定向和服务器迁移 Windows -> Linux

linux - _GLOBAL_OFFSET_TABLE 是什么?

amazon-web-services - 是否可以将 terraform 转换为 AWS CDK?

amazon-web-services - Cloudformation 组合 Sub 和 Join 以获得列表

ssl - 在 lighttpd 配置中访问 X-Forwarded-Proto

authentication - 为什么不允许密码认证?

PHP:重命名没有扩展名的文件

java - 迁移到 Linux 后的 Collections.synchronizedMap(Map) - 第二个线程看不到新条目