12

I have recently installed an ubuntu 16.04. I have installed ssh server and the sshd service is up and running.

I have some other PCs in the same network (windows, mac, ubuntu 14.06) and I can ping the ubuntu pc from all of them, but I cannot connect using ssh from any.

For example, using putty from windows I get a "Network error: Connection Timed out".

Locally I can connect using ssh with the IP.

Any idea of what could be happening?

Thank you in advance for your help!!

Gonzalo.

6
  • 2
    I think you would typically get a connection refused, but have you made sure the firewall is off for testing? 'sudo ufw disable'
    – user508889
    May 3, 2016 at 17:32
  • 1
    Hi Brian, the ufw was enabled. Disabling it allows me to connect, thank you!!!
    – Gonzalo
    May 3, 2016 at 17:37
  • When it is enabled, if I write 'sudo ufw status', it does not show any rules. Do you know why it could be rejecting connections to port 22 if there aren't any rules?!?
    – Gonzalo
    May 3, 2016 at 17:38
  • John, putty have a saved setup, yes. But the same was happening with any ssh client. The issue is related to the firewall.
    – Gonzalo
    May 3, 2016 at 17:40
  • 1
    @Gonzalo the default behaviour is to allow outgoing connections but block incoming ones IIRC - i.e. incoming connections must be explicitly enabled by appropriate rules May 3, 2016 at 17:41

5 Answers 5

29

Instead of turning off your firewall completely, you could instead configure UFW to allow your SSH traffic: sudo ufw allow ssh or if you decide to run SSH on a different port: sudo ufw allow 2222/tcp

UFW by default will deny all incoming connections and allow all outgoing connections. You can find more information on how to configure UFW here: https://help.ubuntu.com/community/UFW

2
  • 3
    This should DEFINITELY be the accepted answer as simply saying "I disabled my firewall" as the accepted answer - is going to wreak havok on others who read it and don't skim down to find they SHOULD NOT do that. Disabling a firewall is never a good idea even if default is block all.
    – Bruce
    May 3, 2017 at 3:52
  • This is the best answer here...
    – PGallagher
    Oct 1, 2019 at 21:07
5

It turned to be that the firewall was enabled.

After executing 'sudo ufw disable' I was able to remotely connect.

Thank you Brian and all for your help.

Regards,

Gonzalo.

1
  • It should be noted that this will certainly make things easier to get working, but completely disabling the firewall is generally not a good idea, so if you can just enable specific ports to be opened then your computer will be much less vulnerable to the internet.
    – gleenn
    Feb 10 at 22:20
1

Other answers have pointed out most of the causes. I would add another reason for not able to ssh. If you ssh by password authentication method, it may be because your password is a bad one. Just update a decent password, it will work. This was driving me crazy to find out...

0

Try port forwarding port 22 if you are trying to connect with a public IP address, because that would be the only reason why you can only connect to it using the local ip address of the server. Also yes if you are using the ufw firewall and it is enabled make sure you have 'ufw allow 22' executed. You can check this by running 'ufw status'.

-2

I ran into the same issue, when I installed ubuntu 18.4. I tried all the above options and it still did not work until I ran the commands below:

1.Checked the ssh status:

sudo service ssh status  

OUTPUT: Failed to restart ssh.service: Unit ssh.service not found.

2.Then installed ssh:

sudo apt-get install ssh
1
  • The question being "cannot connect remotely using ssh" it's assume the OP has it. Jul 30, 2021 at 19:33

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .