I'm trying to connect to the my Raspberry Pi over SSH.

I'm able to do it internally (ssh user@raspberrypi), but when I try to connect externally (over public IP) it says:

port 22: Connection refused

I set up port forwarding in the router and disabled the firewall, but still get the same problem. What other causes can there be?

| improve this question | | | | |
  • 1
    you likely didn't set up port forwarding correctly, or for some reason your ISP blocks port 22. I usually do port translation with port forward, i.e. External IP:port 42020 -> Internal IP:port 22. Then SSH user@externalIP:42020 – Tyson Dec 29 '15 at 19:25
  • Use the port scanner here to see if your port is open from the outside. – Tyson Dec 29 '15 at 20:17
  • Well bad link... Grc.com and the port scanner is the shields up tool – Tyson Dec 29 '15 at 20:19
  • I checked using that tool and it says that 22 and 80 are both open. – Rizhiy Dec 29 '15 at 20:22
  • I also double checked my port forwarding and it appears to be correct. I tried to redirect ports, but still no success. – Rizhiy Dec 29 '15 at 20:24

Below are the most common reasons that users seem to have trouble with an ssh connection.

  1. You haven't enabled forwarding or have enabled it incorrectly

If you don't enable port forwarding from the router, or have configured it incorrectly, the connection will be refused. Instructions on this will vary based on the router, but ensure that the forwarded IP address is the same that the RPi is using.

Also, note that the address can change from time to time. I have my router set to always give my RPi the same address because of this.

  1. Your ISP may disable traffic on port 22

I have never experienced this personally, but some networks block "common home server ports", such as 21 and 22. If they do, there's nothing you can do to enable those ports. Switching to a different port will usually solve this problem, even if it is a bit annoying.

  1. You're trying to connect from the same network

Some routers don't like it when the destination is within the same network. The Motorola I previously rented from Comcast would fail with the same error, but my TP-link manages the connection without an issue.

| improve this answer | | | | |
  • I don't get it. I enabled port forwarding on my Google OnHub router. I registered a subdomain with Google Domains. I set up ddns daemon on my Pi. Why isn't it working? – IgorGanapolsky Aug 15 '16 at 7:36

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