Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/symfony/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Amazon web services 权限被拒绝(公钥)Amazon Linux aws_Amazon Web Services_Authentication_Amazon Ec2_Ssh_Permissions - Fatal编程技术网

Amazon web services 权限被拒绝(公钥)Amazon Linux aws

Amazon web services 权限被拒绝(公钥)Amazon Linux aws,amazon-web-services,authentication,amazon-ec2,ssh,permissions,Amazon Web Services,Authentication,Amazon Ec2,Ssh,Permissions,我有两个实例在aws上运行。我有两个相同的钥匙对。我很长时间都在使用这两个实例。但今天,如果我运行这个命令,在试图通过终端登录时,我在一个实例上遇到了一个错误 ssh -i mypem.pem ec2-user@52.xx.xxx.xxx Permission denied (publickey). 但是如果我尝试使用相同的pem文件登录到其他实例。它的工作,我可以成功登录到它 我已经尝试了这里介绍的所有解决方案 但对我来说什么都不管用 如果我这样做 ssh -i mypem.pem ec

我有两个实例在aws上运行。我有两个相同的钥匙对。我很长时间都在使用这两个实例。但今天,如果我运行这个命令,在试图通过终端登录时,我在一个实例上遇到了一个错误

ssh -i mypem.pem ec2-user@52.xx.xxx.xxx
Permission denied (publickey).
但是如果我尝试使用相同的
pem
文件登录到其他实例。它的工作,我可以成功登录到它

我已经尝试了这里介绍的所有解决方案

但对我来说什么都不管用

如果我这样做

ssh -i mypem.pem ec2-user@52.xx.xxx.xxx -vvv
结果是这样的

    OpenSSH_7.4p1, LibreSSL 2.5.0
debug1: Reading configuration data /etc/ssh/ssh_config
debug2: resolving "52.xx.xxx.xxx" port 22
debug2: ssh_connect_direct: needpriv 0
debug1: Connecting to 52.xx.xxx.xxx [52.xx.xxx.xxx] port 22.
debug1: Connection established.
debug1: key_load_public: No such file or directory
debug1: identity file mypem.pem type -1
debug1: key_load_public: No such file or directory
debug1: identity file mypem.pem-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_7.4
debug1: Remote protocol version 2.0, remote software version OpenSSH_7.4
debug1: match: OpenSSH_7.4 pat OpenSSH* compat 0x04000000
debug2: fd 3 setting O_NONBLOCK
debug1: Authenticating to 52.xx.xxx.xxx:22 as 'ec2-user'
debug3: hostkeys_foreach: reading file "/Users/myusername/.ssh/known_hosts"
debug3: record_hostkey: found key type ECDSA in file /Users/myusername/.ssh/known_hosts:6
debug3: load_hostkeys: loaded 1 keys from 52.xx.xxx.xxx
debug3: order_hostkeyalgs: prefer hostkeyalgs: ecdsa-sha2-nistp256-cert-v01@openssh.com,ecdsa-sha2-nistp384-cert-v01@openssh.com,ecdsa-sha2-nistp521-cert-v01@openssh.com,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521
debug3: send packet: type 20
debug1: SSH2_MSG_KEXINIT sent
debug3: receive packet: type 20
debug1: SSH2_MSG_KEXINIT received
debug2: local client KEXINIT proposal
debug2: KEX algorithms: curve25519-sha256,curve25519-sha256@libssh.org,ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256,diffie-hellman-group16-sha512,diffie-hellman-group18-sha512,diffie-hellman-group-exchange-sha1,diffie-hellman-group14-sha256,diffie-hellman-group14-sha1,ext-info-c
debug2: host key algorithms: ecdsa-sha2-nistp256-cert-v01@openssh.com,ecdsa-sha2-nistp384-cert-v01@openssh.com,ecdsa-sha2-nistp521-cert-v01@openssh.com,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521,ssh-ed25519-cert-v01@openssh.com,ssh-rsa-cert-v01@openssh.com,ssh-ed25519,rsa-sha2-512,rsa-sha2-256,ssh-rsa
debug2: ciphers ctos: chacha20-poly1305@openssh.com,aes128-ctr,aes192-ctr,aes256-ctr,aes128-gcm@openssh.com,aes256-gcm@openssh.com,aes128-cbc,aes192-cbc,aes256-cbc
debug2: ciphers stoc: chacha20-poly1305@openssh.com,aes128-ctr,aes192-ctr,aes256-ctr,aes128-gcm@openssh.com,aes256-gcm@openssh.com,aes128-cbc,aes192-cbc,aes256-cbc
debug2: MACs ctos: umac-64-etm@openssh.com,umac-128-etm@openssh.com,hmac-sha2-256-etm@openssh.com,hmac-sha2-512-etm@openssh.com,hmac-sha1-etm@openssh.com,umac-64@openssh.com,umac-128@openssh.com,hmac-sha2-256,hmac-sha2-512,hmac-sha1
debug2: MACs stoc: umac-64-etm@openssh.com,umac-128-etm@openssh.com,hmac-sha2-256-etm@openssh.com,hmac-sha2-512-etm@openssh.com,hmac-sha1-etm@openssh.com,umac-64@openssh.com,umac-128@openssh.com,hmac-sha2-256,hmac-sha2-512,hmac-sha1
debug2: compression ctos: none,zlib@openssh.com,zlib
debug2: compression stoc: none,zlib@openssh.com,zlib
debug2: languages ctos: 
debug2: languages stoc: 
debug2: first_kex_follows 0 
debug2: reserved 0 
debug2: peer server KEXINIT proposal
debug2: KEX algorithms: curve25519-sha256,curve25519-sha256@libssh.org,ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256,diffie-hellman-group16-sha512,diffie-hellman-group18-sha512,diffie-hellman-group-exchange-sha1,diffie-hellman-group14-sha256,diffie-hellman-group14-sha1,diffie-hellman-group1-sha1
debug2: host key algorithms: ssh-rsa,rsa-sha2-512,rsa-sha2-256,ecdsa-sha2-nistp256,ssh-ed25519
debug2: ciphers ctos: chacha20-poly1305@openssh.com,aes128-ctr,aes192-ctr,aes256-ctr,aes128-gcm@openssh.com,aes256-gcm@openssh.com,aes128-cbc,aes192-cbc,aes256-cbc,blowfish-cbc,cast128-cbc,3des-cbc
debug2: ciphers stoc: chacha20-poly1305@openssh.com,aes128-ctr,aes192-ctr,aes256-ctr,aes128-gcm@openssh.com,aes256-gcm@openssh.com,aes128-cbc,aes192-cbc,aes256-cbc,blowfish-cbc,cast128-cbc,3des-cbc
debug2: MACs ctos: umac-64-etm@openssh.com,umac-128-etm@openssh.com,hmac-sha2-256-etm@openssh.com,hmac-sha2-512-etm@openssh.com,hmac-sha1-etm@openssh.com,umac-64@openssh.com,umac-128@openssh.com,hmac-sha2-256,hmac-sha2-512,hmac-sha1
debug2: MACs stoc: umac-64-etm@openssh.com,umac-128-etm@openssh.com,hmac-sha2-256-etm@openssh.com,hmac-sha2-512-etm@openssh.com,hmac-sha1-etm@openssh.com,umac-64@openssh.com,umac-128@openssh.com,hmac-sha2-256,hmac-sha2-512,hmac-sha1
debug2: compression ctos: none,zlib@openssh.com
debug2: compression stoc: none,zlib@openssh.com
debug2: languages ctos: 
debug2: languages stoc: 
debug2: first_kex_follows 0 
debug2: reserved 0 
debug1: kex: algorithm: curve25519-sha256
debug1: kex: host key algorithm: ecdsa-sha2-nistp256
debug1: kex: server->client cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: none
debug1: kex: client->server cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: none
debug3: send packet: type 30
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug3: receive packet: type 31
debug1: Server host key: mykeyhere
debug3: hostkeys_foreach: reading file "/Users/myusername/.ssh/known_hosts"
debug3: record_hostkey: found key type ECDSA in file /Users/myusername/.ssh/known_hosts:6
debug3: load_hostkeys: loaded 1 keys from 52.70.181.239
debug1: Host '52.xx.xxx.xxx' is known and matches the ECDSA host key.
debug1: Found key in /Users/irfansheikh/.ssh/known_hosts:6
debug3: send packet: type 21
debug2: set_newkeys: mode 1
debug1: rekey after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug3: receive packet: type 21
debug1: SSH2_MSG_NEWKEYS received
debug2: set_newkeys: mode 0
debug1: rekey after 134217728 blocks
debug2: key: mypem.pem (0x7f9053c03750), agent
debug2: key: mypem.pem (0x0), explicit
debug3: send packet: type 5
debug3: receive packet: type 7
debug1: SSH2_MSG_EXT_INFO received
debug1: kex_input_ext_info: server-sig-algs=<rsa-sha2-256,rsa-sha2-512>
debug3: receive packet: type 6
debug2: service_accept: ssh-userauth
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug3: send packet: type 50
debug3: receive packet: type 51
debug1: Authentications that can continue: publickey
debug3: start over, passed a different list publickey
debug3: preferred publickey,keyboard-interactive,password
debug3: authmethod_lookup publickey
debug3: remaining preferred: keyboard-interactive,password
debug3: authmethod_is_enabled publickey
debug1: Next authentication method: publickey
debug1: Offering RSA public key: bringthings.pem
debug3: send_pubkey_test
debug3: send packet: type 50
debug2: we sent a publickey packet, wait for reply
debug3: receive packet: type 51
debug1: Authentications that can continue: publickey
debug1: Trying private key: mypem.pem
debug3: sign_and_send_pubkey: RSA 
SHA256:keyhere**********
debug3: send packet: type 50
debug2: we sent a publickey packet, wait for reply
debug3: receive packet: type 51
debug1: Authentications that can continue: publickey
debug2: we did not send a packet, disable method
debug1: No more authentication methods to try.
Permission denied (publickey).
我也试过这个

sudo ssh -i mypem.pem ec2-xxx-xxx-xxx-xxx.us-west 2.compute.amazonaws.com
明白了吗

Please login as the user "ec2-user" rather than the user "root"
然后我做了这个

sudo ssh -i mypem.pem ec2-xxx-xxx-xxx-xxx.us-west-2.compute.amazonaws.com -l ec2-user
我得到

Permission denied (publickey)
如果我尝试使用相同的密钥登录到其他实例。我可以成功登录。请帮忙到底出了什么问题

我的实例上的安全组是


与ec2的故障排除连接:

您还可以尝试三重冗余选项-vvv


我经常会遇到同样的错误,通常我使用的是ec2用户而不是ubuntu或者错误的密钥,你可以尝试前面建议的
-vvv
选项,看看是否能获得更多关于SSH失败原因的信息

如果仍不清楚,则唯一的选择是将卷从当前实例分离,并将其附加到另一个EC2实例,装载卷并检查以下日志文件中是否有任何错误消息:-

/var/log/messages
/var/log/secure
关于如何分离卷并将其附加到另一个EC2实例,您可以使用以下链接作为参考:-

https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ebs-detaching-volume.html 
https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ebs-attaching-volume.html
分离和连接时,记下卷的设备名称,如
/dev/xvda
/dev/sda1
。如果您第一次错过了,然后又不得不重复整个分离和连接过程,这是非常恼人的

这里的错误可能有几个原因。例如,如果在服务器关闭之前的最后一次期间,
/home/ec2 user/.ssh
文件夹或其上存在的任何文件的权限设置不正确,则该命令将无法读取文件,因此将失败。通常,记录在日志文件中的错误很有用,并且能够提供不可访问性的原因

我想指出的一点是,您正在使用两个密钥对名称:
amazonec2.pem
mypem.pem
。在使用
mypem.pem
时,您提到了用户名:
ec2 user
以及SSH命令中的IP地址。但是,当您使用
amazonec2.pem
时,命令中缺少它

请注意,如果用户名不存在,则该命令实际上将无法授予相同的
权限拒绝(publickey)。
错误。我试图SSH到我的EC2实例中,但没有提到用户名,结果失败了


希望这能有所帮助。

就我而言,我多次输入了错误的密码短语。之后我不断地被拒绝。
我重新启动了我的AWS实例,并尝试了同样有效的凭据。

问题是因为使用了不同的公钥,并且为了解决此问题:-

只需使用私钥创建一个公钥,即mypem.pem文件,如下所示:-

ssh-keygen-y-f mypem.pem

它将为私钥创建并显示公钥 您只需将此密钥复制到aws实例中,如下所示:-

如果您正在运行ubuntu实例,请打开授权密钥文件,并将生成的公钥粘贴到该文件中(删除现有内容):-

vi~/.ssh/authorized_key

然后尝试使用以下命令连接:-

ssh-i mypem.pem ec2-user@52.xx.xxx.xxx


ssh-i mypem.pemubuntu@52.xx.xxx.xxx

对不起,“amazonec2.pem和mypem.pem”这只是一个打字错误。我在任何地方都使用相同的mypem.pem,然后,你必须分析日志文件,ssh的
-vvv
输出是什么意思,你可以在这里更新输出,这样每个人都可以看到并帮助他们,如果他们有提示的话!它们都是AWS Linux实例吗?如果不是,用户名将不同(例如,对于Ubuntu实例,它是“Ubuntu”而不是“ec2用户”)。您是否能够登录到第二个实例?如果是,是否可能是您做了一些更改
.ssh/authorized_keys
?另一个实例的用户名为ubuntu,但此实例的用户为ec2。。是的,我可以成功登录到其他实例,直到晚上一切正常。当我醒来时,它停止了工作。所以我什么都没做
https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ebs-detaching-volume.html 
https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ebs-attaching-volume.html