-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).
Alex Turner
  • 17
  • 1
  • 5
  • 22/TCP is the default SSH port [wikipedia list of ports](https://en.wikipedia.org/wiki/List_of_TCP_and_UDP_port_numbers). I suspect that your SSH daemon is listening to port `21`. Port `21` is the control port for [ftp](https://en.wikipedia.org/wiki/File_Transfer_Protocol) but the data port `20` is missing. Check you `/etc/ssh/sshd_config` for port settings. In case you decide so run your ssh daemon on an port other than `22` you need to reflect that in your `ufw` config as well. You might want to run `netstat -tulpn | grep -i ssh` as `root` as your `netstat` command does not list the process. – Henrik Pingel Oct 19 '15 at 13:08
  • Port 22 is now listening but we are getting the following message: Ubuntu 14.04.2 LTS Permission denied (publickey). – Alex Turner Oct 19 '15 at 13:24
  • That error message means your ssh server is not accepting your key. Enable password authentication and copy your key with `ssh-copy-id` – Henrik Pingel Oct 19 '15 at 13:39
  • 2
    Welcome to [sf]. This is not a forum, and as a result, changing your question to be significantly different does not work well here. In addition you are expected to make at least some attempt to understand your problem before posting here. See the now-linked question for several possibilities. – Michael Hampton Oct 19 '15 at 16:56

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.

sam_pan_mariusz
  • 2,053
  • 1
  • 12
  • 15
  • Port 22 is now listening but we are getting the following message: Ubuntu 14.04.2 LTS Permission denied (publickey). – Alex Turner Oct 19 '15 at 13:24
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,524
  • 7
  • 32
  • 51
pranav
  • 11
  • 2
  • Port 22 is now listening but we are getting the following message: Ubuntu 14.04.2 LTS Permission denied (publickey). – Alex Turner Oct 19 '15 at 13:24
  • run ssh with -v option which is verbose mode and provide the result for more clarification – pranav Oct 20 '15 at 08:29