-1

We are running ubuntu 14.04 with openssh client & server installed. However when trying to connect to port 22 we get 'connect to host localhost port 22: Connection refused’.

Port 22 is open on our firewall, which we thought would've solved our issue.

We have added rules to ufw and purged/reinstalled openssh. When using the command ‘sudo service ssh status’ it says ssh is running however when using commands ‘netstat', 'ps -A | grep sshd', 'sudo ss –lnp | grep sshd’ we get no message. When testing ‘ssh –v localhost’ we also get connection refused.

We have restarted ssh many times but the problem still remains.

Also when we use the command 'sudo iptables -L' we get the following output:

target     prot opt source               destination         
ACCEPT     tcp  --  anywhere             anywhere             tcp dpt:ssh
ACCEPT     tcp  --  anywhere             anywhere             tcp dpt:ssh

We also ran the command sudo netstat -tulpn and this is what we get:

tcp        0      0 0.0.0.0:139             0.0.0.0:*               LISTEN      -               
tcp        0      0 127.0.0.1:5939          0.0.0.0:*               LISTEN      -               
tcp        0      0 0.0.0.0:21              0.0.0.0:*               LISTEN      -               
tcp        0      0 127.0.1.1:53            0.0.0.0:*               LISTEN      -               
tcp        0      0 127.0.0.1:631           0.0.0.0:*               LISTEN      -               
tcp        0      0 0.0.0.0:445             0.0.0.0:*               LISTEN      -               
tcp        0      0 127.0.0.1:3306          0.0.0.0:*               LISTEN      -               
tcp6       0      0 :::139                  :::*                    LISTEN      -               
tcp6       0      0 :::80                   :::*                    LISTEN      -               
tcp6       0      0 ::1:631                 :::*                    LISTEN      -               
tcp6       0      0 :::445                  :::​*                    LISTEN      -            tcp        0      0 0.0.0.0:139             0.0.0.0:*​               LISTEN      -               
tcp        0      0 127.0.0.1:5939          0.0.0.0:*               LISTEN      -               
tcp        0      0 0.0.0.0:21              0.0.0.0:*               LISTEN      -               
tcp        0      0 127.0.1.1:53            0.0.0.0:*               LISTEN      -               
tcp        0      0 127.0.0.1:631           0.0.0.0:*               LISTEN      -               
tcp        0      0 0.0.0.0:445             0.0.0.0:*               LISTEN      -               
tcp        0      0 127.0.0.1:3306          0.0.0.0:*               LISTEN      -               
tcp6       0      0 :::139                  :::*                    LISTEN      -               
tcp6       0      0 :::80                   :::*                    LISTEN      -               
tcp6       0      0 ::1:631                 :::*                    LISTEN      -               
tcp6       0      0 :::445                  :::*                    LISTEN      -

EDIT/UPDATE

The port 22 is now listening but we get the following error when trying to connect via ssh on a mac, localhost ssh works:

Ubuntu 14.04.2 LTS
Permission denied (publickey).

2 Answers2

2

OpenSSH daemon (nor any other) isn't listening on port 22/TCP. It likely fails to start; check your logs, or try to run it from command line with /usr/sbin/sshd -4 -d and check messages.

EDIT: To solve the authentication issue, you probably want to enable password-based authentication in /etc/ssh/sshd_config, or generate a keypair on the client and add the public key (id_rsa.pub by default) to $HOME/.ssh/authorized_keys of the target account.

1

As netstat does not show port 22 is bound, you may have got problem in configuration file check /etc/ssh/sshd_config file to see if it is blocking connection or its running on another port and then restart the service by service sshd restart

Nixphoe
  • 4,624
pranav
  • 11