SSH Connection closed by remote host : Having Security Group SSH Inbound permission set to specific IP address

vj01 picture vj01 · Feb 22, 2016 · Viewed 14.6k times · Source

I am trying to connect to AWS EC2 server from local system using SSH. It is connecting to instance when Security group Inbound permission for SSH is given as connect from anywhere. But whenever it is given specific IP address, it is giving Connection closed by remote host . I'm getting following error while connecting.

sudo ssh -vvv -i {$pemfile} ubuntu@{domain_name}

OpenSSH_6.6.1, OpenSSL 1.0.1f 6 Jan 2014
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug2: ssh_connect: needpriv 0
debug1: Connecting to {HOST_NAME HERE} port 22.
debug1: Connection established.
debug1: permanently_set_uid: 0/0
debug3: Incorrect RSA1 identifier
debug3: Could not load "{KEY_PATH HERE}" as a RSA1 public key
debug1: identity file {KEY_PATH HERE} type -1
debug1: identity file {KEY_PATH HERE} type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_6.6.1p1 Ubuntu-2ubuntu2.6
ssh_exchange_identification: Connection closed by remote host

Answer

Sanket Patel picture Sanket Patel · Feb 22, 2016

Are you giving your IP correct? You might be using IP you get from something like http://formyip.com/ and what EC2 instance is getting might be different one.

Try following:

  1. Change setting to: Allow all IP
  2. SSH into your instance
  3. See the logs at /var/log/auth.log (not very sure about this logfile location)
  4. Identify your IP for last successful login attempt (which might or might not be same as you got from above website)
  5. Use IP from logs (if different) in security group settings
  6. TRY AGAIN :D