My RPi 2 died and was replaced with RPi 3. Disk image of old SD card was deployed on a new card of higher capacity. After inserting that card to my new Raspberry Pi 3, it boot up successfully and accepted a local ssh connection. But when I try to ssh via internet, I get a message "connection refused". Sadly, I replaced the router as well. However, I think the problem is in Pi cause I get this error only when port forwarding points on the Pi. For example, if port 25 forwards packets to (ip of Pi), then ssh pi@ -p 25 causes "connection refused" message, the same command with any other port causes nothing. And ssh [email protected] successfully connects me to the Pi. Port forwarding is set up correctly cause MPoD client successfully connects to my Pi via internet as well as my own iOS app using websockets. Firewall and all security stuff is turned off on the router.

  • Did you setup the RPi to accept ssh connections on port 25?
    – Jacobm001
    Feb 23, 2017 at 23:30
  • Firewall and all security stuff is turned off on the router. I implore you to turn it back on.
    – Jacobm001
    Feb 23, 2017 at 23:30

1 Answer 1


If you connect to your Raspberry without naming the port to be used it normally uses port 22. You're using that to connect to it locally, right?

ssh [email protected]

That means your Raspberry accepts connections over port 22. However, if you add -p 25 it will try port 25 but it seems that it's not configured to use that one.

You should take a look into your ssh configuration to see which port is activated and you should look into the port forwarding settings on your router as it might forward it to the wrong port. If you have your router forward port 25 to your Raspberry for ssh it won't work if ssh isn't configured to use port 25. You should either change your configuration to use port 25 or you should forward port 22 to your Raspberry.

Btw, your command

ssh pi@ -p 25

is not going to work as you don't have an IP or hostname specified. But I'm sure you noticed that too :)

Hope this helps.

  • Thank you Gian, I actually put "rpiLocalIp" in brackets after @, but stackexchange cut it out. As for your answer, previously I used port 25 to ssh to pi both locally and remotely (with forwarding 25 to pi ip), but now it's not working for some reason. However, I forwarded port 22 to pi ip and now I can ssh it remotely without specifying the port.
    – madfatcat
    Feb 22, 2017 at 10:32
  • I'm glad it's working for you now. If you still want to do it over port 25 you'd need to set that in your /etc/ssh/sshd_config file and just forward that port. Feb 22, 2017 at 10:36

Your Answer

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

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