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.


1 Answer 1


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 for "B" and for "C". The router also has his own IP addresses one internal (ex. and one external (ex. 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

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:

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 (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

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.

  • 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.
    – Michael
    Aug 1, 2015 at 2:33
  • I am glad I could clear things up. If You have any questions, feel confident to ask. Have a nice day :-)
    – Divin3
    Aug 1, 2015 at 3:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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