0

When I ssh ( Openssh (7.2p2 ) to (Ubuntu 16.04) server from the (Ubuntu 18.04) workstation for the first time I get the following message "connect to address x.x.x.x port nnnnn Connection refused" (port 22 is not being used ) and ufw has been set to allow the port number being used.

1 Answer 1

0

Make sure your sshd.service is running:

$ systemctl status sshd

If it is not running, run it:

$ sudo systemctl start sshd

Connection refused could be because of the service is not running, the port is wrong or firewall could block it.

You could allow ssh by the next command:

$ sudo ufw allow ssh

Check if your service is actually running on specified port (replace 22 to your own specified port):

$ sudo lsof -i -n -P | grep "22 "
cupsd       791            root    7u  IPv4  27822      0t0  TCP 127.0.0.1:631 (LISTEN)
sshd      10927            root    3u  IPv4 135947      0t0  TCP *:22 (LISTEN)
sshd      10927            root    4u  IPv6 135949      0t0  TCP *:22 (LISTEN)

Check if you could connect to localhost first:

$ ssh user@localhost -p 22
Welcome to Ubuntu 20.04 LTS (GNU/Linux 5.4.0-29-generic x86_64)
1
  • Thanks for the tips which will become useful later on. I had to purge the installation using apt-get purge openssh-server and then re-install. Purging seemed to work better than re-installing although I think your comments would have helped had I known about them at the time. I seem to be getting another problem and that of the system appearing to login Ok but defaults to the client installation. Any ideas? Thanks again.. May 13, 2020 at 11:38

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.