I am running xubuntu 16.04. I am trying to connect to my machine through SSH, from the www.

I have tested ssh successfully through lan, so I know the ssh server is running correctly.

I then went into my router settings, went to Firewall->Allowed Applications, and forwarded a specific port to my linux machine. It asked me to choose a protocol, so selected TCP. After this failed I also tried UDP.

I then tried connected using my android phone on JuiceSSh. I entered in the public IP addr displayed by whatsmyip.com which was corroborated by my routers displayed public IP. I then disconnected my phone from lan. I confirmed my phone does have internet connection.

So anyways, at this point the connection failed, and I am not sure why, or what my next step should be in diagnosing this.

If I changed from my custom port, to just port 22, the connection succeeded. Could this be an issue on my linux servers ssh configuration?

  • What specific port did you forward? Note: Your ISP could be blocking ports anyway. – cricket_007 Feb 11 '17 at 6:15
  • This part : "It asked me to choose a protocol, so selected TCP. After this failed I also tried UDP." looks to me as an issue. Either you already used the same port for another forwarding or didn't finish forwarding setup (Some weird routers require first to "apply changes" and "save" config or some sort of combinations like that) – Alex Feb 11 '17 at 7:20
  • I finished the process correctly. I then completely reverted and finished the process correctly as a different protocol. I forwarded port 2222. – ScottF Feb 11 '17 at 15:51
  • -1 you wrote no error messages anywhere. Also before even attempting SSH port forwarding, you should try just connecting to an SSH shell and checking that you can do that. And doing that will involve NAPT TCP port forwarding on your NAT/NAPT router. – barlop Feb 11 '17 at 16:45
  • I received no error messages. And what do you mean "You should try connecting to an SSH shell". That is an incomplete statement. – ScottF Feb 11 '17 at 16:59

To make sure your ISP, or modem in front of your router are not responsible, try connecting to your machine using routers IP. So, after you've set up port forwarding:

ssh ScottF@192.168.x.x -p 2222

If you are using a password to connect (which is common when using JuiceSSH), make sure that your /etc/ssh/sshd_config allows password authentication from your phone's public IP address: PasswordAuthentication yes.

If you are trying to connect as root, you need to allow external root login: PermitRootLogin yes

Don't forget to restart your ssh server after each important change in settings:

sudo service ssh restart

  • Can you elaborate on your first point? Do you mean try connecting to my machine over lan? I did that already and mentioned it in the post. – ScottF Feb 11 '17 at 17:30
  • I assumed you connected directly, using your ssh server's local IP. Using gateway's IP, you'll be able to catch if the problem is in your configuration, or in external access to your router. – doriclazar Feb 11 '17 at 17:44
  • I connected to my ssh server successfully though LAN 192.168.... – ScottF Feb 11 '17 at 18:18
  • So you connected to WiFi with your phone, used gateway's LAN IP ( which is forwarding ssh traffic to your machine ( – doriclazar Feb 11 '17 at 18:29
  • If your error was based on remote connection permissions, you would get an error message. This leaves us with either router's firewall or ISP blocking port 2222. If your router's firewall is turned on, you just need to create a rule that allows usage of this port. Good luck! – doriclazar Feb 11 '17 at 18:36

The problem was that although I was forwarding port 2222 to my linux server, I did up update the /etc/ssh/sshd_config file to listen on port 2222. Once I updated the config to listen on the correct port, I was able to connect correctly.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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