简体   繁体   中英

Amazon Linux AMI ec2 instance Permission denied (Public key)

I have a recurring problem with one instance in AWS.

The problem is as follows:

The instance is an Amazon Linux AMI, that contains a Tomcat 6 Server and also has an SFTP connection enabled.

We can connect via ssh without any problem, but suddenly without any technical intervention we stop being able to connect with ssh. The Tomcat is still available and the sftp connection is still on.

This problem has already happened sometimes and now is happening more frequently and the post in AWS Forums resolve nothing.

The ssh traces are these:

OpenSSH_7.1p2, OpenSSL 1.0.1g 7 Apr 2014
debug1: Reading configuration data /etc/ssh_config
debug1: Connecting to xxx.xxx.xxx.xxx [xxx.xxx.xxx.xxx] port 22.
debug1: Connection established.
debug1: key_load_public: No such file or directory
debug1: identity file xxxxxxxxxx.pem type -1
debug1: key_load_public: No such file or directory
debug1: identity file xxxxxxxxxx.pem-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_7.1
debug1: Remote protocol version 2.0, remote software version OpenSSH_6.2
debug1: match: OpenSSH_6.2 pat OpenSSH* compat 0x04000000
debug1: Authenticating to xxx.xxx.xxx.xxx:22 as 'ec2-user'
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-ctr hmac-md5 zlib@openssh.com
debug1: kex: client->server aes128-ctr hmac-md5 zlib@openssh.com
debug1: sending SSH2_MSG_KEX_ECDH_INIT
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ssh-rsa     SHA256:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
debug1: Host 'xxx.xxx.xxx.xxx' is known and matches the RSA host key.
debug1: Found key in /home/mobaxterm/.ssh/known_hosts:21
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: Trying private key: xxxxxxxxx.pem
debug1: Authentications that can continue: publickey
debug1: No more authentication methods to try.
Permission denied (publickey).

The ssh configuration hasn't changed, the .pem file hasn't changed, the IP hasn't changed. We have tested it from different devices and the result is the same. We use the ec2-user properly.

Terminal, Moba Xterm, Jenkins, Putty, Pac Manager can't connect via ssh.

We have the same configuration is other instances and this is the only one that suffers this issue.

The instance is a r3.xlarge and it is located in us-east-1c, it is linked with a static ip.

Thanks a lot.

I don't know why, but there is something that is deleting the ec2-user's authorized_keys file ( /home/ec2-user/.ssh/authorized_keys ). If you have a copy of this file and create it again in the original instance the problem will be solved.

Now I only need to know why this file was deleted, and how it happened.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM