Every time I try to connect via SSH using "ssh user@ip" I get this error:

ssh: connect to host 192.168.80.131 port 22:Connection refused

I check to see if I have my router set up for port forwarding and I guess I do:

enter image description here

I checked if I have my server set up for port forwarding:

tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN     
tcp6       0      0 :::22                   :::*                    LISTEN

I also checked to see if my firewall is configured:

To                         Action      From

20                         ALLOW       Anywhere                  
22                         ALLOW       Anywhere                  
80                         ALLOW       Anywhere                  
23                         ALLOW       Anywhere                  
8080                       ALLOW       Anywhere                  
20 (v6)                    ALLOW       Anywhere (v6)             
22 (v6)                    ALLOW       Anywhere (v6)             
80 (v6)                    ALLOW       Anywhere (v6)             
23 (v6)                    ALLOW       Anywhere (v6)             
8080 (v6)                  ALLOW       Anywhere (v6)

I also have ssh, openssh-client, openssh-server installed on my server.

Also I would like to mention that the client from where I am connecting to the server is connected to the router via LAN and the server is connected to the router via Wi-FI.

  • 1
    It's not totally clear what's going on here. You might want to add more background. What ssh command are you using, e.g. ssh -p 2222 192.168.80.131. – igal Oct 29 '17 at 18:37
  • 1
    Are you trying to connect your LAN machine from the Internet by using the command: ssh 192.168.80.131 ... if so, that's the first problem. It also looks like you have a NAT problem where external port 2222 should be mapped to internal port 22, since that is the port being used by your internal running ssh. – RubberStamp Oct 29 '17 at 19:29
  • I'm sorry, could you please expand a bit on the NAT problem, I am not sure what that means. – Di Nu Oct 30 '17 at 8:28
  • I edited my original post, It seems that I had a mistake in it, it was supposed to have an error containing port 22 not 2222. Sorry about that. – Di Nu Oct 30 '17 at 8:31

According to your problem statement, you get the following error:

ssh: connect to host 192.168.80.131 port 2222:Connection refused

This suggests that you're trying to connect to the server on port 2222, e.g. that you're using a command like the following one:

ssh -p 2222 192.168.80.131

You also posted the following list of firewall rules:

20 ALLOW Anywhere
22 ALLOW Anywhere
80 ALLOW Anywhere
23 ALLOW Anywhere
8080 ALLOW Anywhere
20 (v6) ALLOW Anywhere (v6)
22 (v6) ALLOW Anywhere (v6)
80 (v6) ALLOW Anywhere (v6)
23 (v6) ALLOW Anywhere (v6)
8080 (v6) ALLOW Anywhere (v6)

It looks like port 2222 is missing from this list.

You also posted a screen-shot of what appears to be your router's administrative GUI which shows a port-forwarding configuration page which included SSH rules for both port 22 and port 2222. You haven't included enough information for me to determine exactly what your network looks like, but it appears that you'd like to connect to a host on one of these two ports.

Two obvious next-steps come to mind:

  1. Try connecting on port 22, e.g. ssh 198.168.80.131, or

  2. Try adding an ALLOW rule for port 2222 (via your router's administrative GUI) before trying to connect on port 2222 again.

  • Hi,thank you very much for your answer, I posted the wrong message, I usually get port 22 error "ssh: connect to host 192.168.80.131 port 22:Connection refused" but at that point I tried connecting to port 2222 with some "tweeking". The command I am using is "ssh user_name@192.168.80.131". – Di Nu Oct 30 '17 at 8:24
  • Also I modified my post to reflect that and I added the correct error message. Maybe I should also mention that I am trying to connect from the same router just too different computers, so I have one computer that is connected to the router via LAN which would be the client and one that is connected via WIFI which would be the server, Im not sure how relevant that is but... If you need more info please let me know – Di Nu Oct 30 '17 at 8:34
  • I read about something called "Bridge", Im not sure if I have that set up or if I should set that up... – Di Nu Oct 30 '17 at 8:46
  • @DiNu Why are you using port-forwarding? Also, can you ping one computer from the other? – igal Oct 30 '17 at 12:25
  • I thought that is the way to do it, use prot-forwarding to use ssh. No I cannot, if I try "ping 192.168.80.131" from the client it does nothing... – Di Nu Oct 30 '17 at 14:21

Check the following

  1. Edit /etc/ssh/sshd_config to listen on Port 2222.

  2. Make sure there is no # in front of the Port number(this comments/cancels out anything but defaults)

  3. Allow port 2222 through your firewall as changing the port from 22 to 2222 does not change it automatically for most firewall profiles.

  4. When using ssh on any other port but 22 your command will have to be something like this ssh user@host -p 2222

  • Thank you very much for your response, I have tried this and its still the same problem :( – Di Nu Oct 30 '17 at 10:02
  • Have you reset sshd after making changes? service sshd restart or systemctl restart sshd? Like wise with your router and fire wall? – m_krsic Oct 30 '17 at 17:08
  • yes, I have restarted all of them, still no change... – Di Nu Oct 30 '17 at 17:35
  • Change them to 50000 or higher. Your router may have some ports reserved. Also try and enter a single value not a range, ie. just 2222 not 2222-2222. Try and only put the port number into sshd. No addresses, comment them out with the # – m_krsic Oct 30 '17 at 19:38

Try using:

ssh user@host -p 'port'

where 'port' is ether 22 or 2222. I don't know which port is the actual one you're using right now, 2222 or 22. If you don't know send sshd_config

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.