I want to be able to directly connect from anywhere to an embedded linux (called C) which doesn't have a public IP address.

C can set up a connection to the server (with SSH -R), and if I SSH into the server, I can then SSH into the embedded linux.

However, I'd like to be able to SSH from client to C without having to first SSH into the server. (I can't set up a connection with SSH -R from C to client)

Is this possible, if so, how?

2 Answers 2


You can do this fairly easily. One way is to use SSH's remote port forwarding, by which C is telling the server to forward a port back to it, something like:

ssh -R 2222:localhost:22 server

This command, when run from C, will tell the server to take any connection to port 2222 and forward them to C on port 22.

Likewise, you could set up port forwarding on the server via firewall rules.

  • No. This will still listen on localhost, which is obviously not accessible from outside.
    – Jakuje
    May 26, 2017 at 8:44

If you want to be able to connect to the forwarded port, you need four things:

  • Specify the server public IP/hostname as the first argument to -R, otherwise it will be listening only on localhost, which is obviously not accessible from outside of the server.
  • Configure the server with GatewayPorts, which will allow the forwarded ports to be accessible from outside
  • Use the -g switch to basically allow the same from client side
  • Open the port 2222 in the server firewall.

The command can look like this:

ssh -g -R server:2222:localhost:22 server

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .