Yesterday connection to AWS server was working fine but today I'm trying to connect using the command prompt with the following:

ssh -i <mypemfile.pem> ubuntu@<my-ip-address>

I've got the error:

connection closed by IP address

I also changed the inbound rule in my security group.

I've tried to connect with filezilla, putty, winscp with no success. please help me find out the issue.

I am do from google like

ssh -v -i <mypemfile.pem> ubuntu@<my-ip-address>

it will display the following

OpenSSH_6.6.1, OpenSSL 1.0.1m 19 Mar 2015
debug1: Connecting to [] port 22.
debug1: Connection established.
debug1: identity file instacare.pem type -1
debug1: identity file instacare.pem-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_6.6.1
debug1: Remote protocol version 2.0, remote software version OpenSSH_6.6.1p1 Ubu
debug1: match: OpenSSH_6.6.1p1 Ubuntu-2ubuntu2 pat OpenSSH_6.6.1* compat 0x04000
debug1: SSH2_MSG_KEXINIT sent
Connection closed by

I am also checking with telnet 22 it will display the following line and get stuck

SSH-2.0-OpenSSH_6.6.1p1 Ubuntu-2ubuntu2

Please help me to find out what is I am doing wrong.

  • 1
    It sounds like your instance has consumed all its available memory. You may be able to confirm this by viewing the system log in the AWS web console, and if so, the only obvious solution will be to reboot the instance (again, from the web console). – Michael - sqlbot Sep 3 '15 at 10:02
  • Thanks for reply. how i can see web console can you tell me please? – Paresh Gami Sep 3 '15 at 11:17
  • 1
    from the AWS UI: right click on your instance, go over "instance settings" and then "get system log" – Tom Sep 3 '15 at 12:31
  • I had the same issue and inbound rules were also proper but only thing I had mistaken that is my instance username (ex:ubuntu or ec2-user). After putting the right username the issue was solved. – Asad Feb 22 '19 at 2:46

This often happens because of lack of either memory RAM or Disk Space, which are used to allocate your new session. You can fix this by restarting your instance or wait for it to free some resources (which is unlikely)

  • Yeap, this happened to me while trying to build an open source library on a cloud instance with only 1GB of RAM, without knowing that around 4GB of RAM are needed for that build, and without knowing that running out of memory causes the SSH connections to be unexpectedly closed by the remote host. – Sorin Postelnicu Dec 26 '18 at 19:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.