ssh: connect to host port 22: Connection refused

6,129

So I made a picture to illustrate our current state and help the explanation.

enter image description here

"A" is the computer at home, "B" is the computer at work, "C" is another computer at work.

"C" does have access to "B".

"A" does not have access to "B" and this is our problem that has to be solved.

The most common reason for this is that "B" and "C" are in the same network, "A" has to get trough the router to be able to access "B" or "C".

"B" and "C" has local IP addresses lets say for example 192.168.13.10 for "B" and 192.168.13.20 for "C". The router also has his own IP addresses one internal (ex. 192.168.13.1) and one external (ex. 10.10.10.11) that can be reached over the internet.

"B" and "C" can talk to each other with ease by calling each other over the local IP address, since they are in the same network if "C" wants to talk to "B" over port 22 all he has to do is open communication on 192.168.13.10:22.

It gets a bit more complicated when "A" wants to reach "B" or "C", since there is only one IP address that can be accessed over the internet, and that is the routers external IP address: 10.10.10.11.

What happens here is, there has to be a port forwarding on the router meaning that, lets say we want to forward all the information that the router gets on port 12345 to the port 22 of "C". So we must set up the routers port forwarding saying that inbound connection on port 12345 to be forwarded to 192.168.13.20:22 (address of computer "C")

From now on, if I want to access the port 22 of computer "C" from an external computer, I just have to connect to 10.10.10.11:12345


so in order for this to work and to be able to access computer "B" from computer "A", we must have a port forwarding in the router on a free port that refers to the internal address of computer "B"s port 22.

Share:
6,129
Michael
Author by

Michael

Updated on September 18, 2022

Comments

  • Michael
    Michael over 1 year

    I am trying to ssh into my new Raspberry Pi using MobaXterm but I keep getting the following error: ssh: connect to host ... port 22: Connection refused.
    Both the PC and Raspberry Pi have wired connections to the router and I can successfully ping the Raspberry Pi. I also have the same problem with Putty.

    To test my connection I have also tried logging into the supercomputer at work through MobaXterm but it returns the same error. I know for a fact that ssh is running on this computer as I am able to ssh into it from my work computer. I have checked and my ISP does not block port 22, I have tried disabling the firewall, port forwarding , etc and nothing has worked. I don't have a monitor with a hdmi connection so therefore I am unable to test if I can log into the computer at work using the Raspberry Pi. I would appreciate any suggestions. Thanks in advance.

  • Michael
    Michael almost 9 years
    I have since managed to get access to the Raspberry Pi after a clean installation. I had assumed it was the same problem stopping me from connecting to both but it's now clear to me the extra complications of trying to ssh to a PC outside my local network. Thank you for the clear explanation. It is now pretty late but I will go through this properly tomorrow morning.
  • Divin3
    Divin3 almost 9 years
    I am glad I could clear things up. If You have any questions, feel confident to ask. Have a nice day :-)