I'm not a guru of ssh but somehow I cannot connect to server with IP and username:


Response is always:

Connection closed by [SERVER_IP]

The problem is on the remote server side?

I'm on Mac OS X (mavericks).

update: log looks as follows:

debug1: Reading configuration data /etc/ssh_config
debug1: /etc/ssh_config line 20: Applying options for *
debug2: ssh_connect: needpriv 0
debug1: Connecting to [SERVER_IP] port 22068.
debug1: Connection established.
debug3: Incorrect RSA1 identifier
debug3: Could not load "/Users/dmitri/.ssh/id_rsa" as a RSA1 public key
debug1: identity file /Users/dmitri/.ssh/id_rsa type 1
debug1: identity file /Users/dmitri/.ssh/id_rsa-cert type -1
debug1: identity file /Users/dmitri/.ssh/id_dsa type -1
debug1: identity file /Users/dmitri/.ssh/id_dsa-cert type -1
debug1: Enabling compatibility mode for protocol 2.0 
debug1: Local version string SSH-2.0-OpenSSH_6.2
debug1: Remote protocol version 2.0, remote software version OpenSSH_5.9p1 Debian-5ubuntu1.1
debug1: match: OpenSSH_5.9p1 Debian-5ubuntu1.1 pat OpenSSH_5*
debug2: fd 3 setting O_NONBLOCK
debug3: put_host_port: [SERVER_IP]:22068
debug3: load_hostkeys: loading entries for host "[SERVER_IP]:22068" from file "/Users/dmitri/.ssh/known_hosts"
debug3: load_hostkeys: loaded 0 keys
debug1: SSH2_MSG_KEXINIT sent

ANOTHER UPDATE: sshd_config

Port 22068
Protocol 1,2 
# HostKeys for protocol version 2
HostKey /etc/ssh/ssh_host_rsa_key
HostKey /etc/ssh/ssh_host_dsa_key
HostKey /etc/ssh/ssh_host_ecdsa_key
  • What is the output if you at '-vvv' to the command? ssh -vvv -p [PORT] [USERNAME]@[SERVER_IP]
    – jasperado
    Jun 23, 2014 at 9:21
  • @jasperado check update with log please
    – Kosmetika
    Jun 23, 2014 at 9:30
  • Which OS is running on the server? Do you have access to the server (other than the not working ssh)?
    – jasperado
    Jun 23, 2014 at 9:39
  • @jasperado Ubuntu 12.04
    – Kosmetika
    Jun 23, 2014 at 9:40
  • @jasperado yes I have access to the server
    – Kosmetika
    Jun 23, 2014 at 9:41

4 Answers 4


I would try debugging this problem differently. Since you have access to the server, run the ssh server manually with the -d (for debug) option:

  sudo service ssh stop
  sudo /usr/sbin/sshd -ddd

This will increase the verbosity level of the server, just like the -vvv option for the client. The output of the second command will go to standard error,you may capture it, analyze, and, if in doubt, post the last lines here for further discussion.

You can also use another command,

 sudo /usr/sbin/sshd -T

to check the validity of your configuration and of your keys.

You sdirectory hould also check the permissions you have, on the client and on the server, for the .ssh for the users from whom and to whom you are connecting (use 700=, the existence of an authorized_keys file in the .ssh directory of the user you are connecting to, and the permissions for the keys in the .ssh directory of the client (they should be 700).


sudo service ssh stop points me to stop: Unknown instance:

This means you do not have an ssh server running on your Ubuntu machine. Have you downloaded the package ssh? Does it start correctly? Try running it with the command I gave above,

  sudo /usr/sbin/sshd -d

and check its output

  • sudo service ssh stop points me to stop: Unknown instance:
    – Kosmetika
    Jun 23, 2014 at 15:36
  • @Kosmetika This means you do not have an ssh server running on your Ubuntu machine, pkease see the edit to my post. Jun 23, 2014 at 16:54

Check the permissions on the /etc/ssh_host_rsa_key and /etc/ssh_host_dsa_key files. They must be 0600. I had the same problem and nothing worked. But when I did a

sudo /usr/sbin/sshd -d

I got a bunch of error messages nagging about those 2 files (that their 0644 permission was “too open”). Everything was fixed by giving those 2 commands:

sudo chmod 600 /etc/ssh_host_rsa_key
sudo chmod 600 /etc/ssh_host_dsa_key

Yes, this is a 'problem' on the remote side. The error suggests that a connection is made, but then closed by the server. There are several things you could check:

  • Check for access lists/other security controls in /etc/ssh/sshd_config
  • Check TCP wrappers (/etc/hosts.allow, /etc/hosts.deny)
  • you can check log update where I ran command with -vvv option, any ideas?
    – Kosmetika
    Jun 23, 2014 at 9:36

In case it helps anyone else, my problem when I received this error was client side. I had mistyped the [USERNAME] portion of the command.

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.