I have two machines A and B which are in different subnets, both behind separate firewalls. Machine A can see B, but B cannot see A. I have a user account (non-root) on both machines, I can SSH B from A, and I would like to be able to SSH A from B instead, but that cannot be done directly.

I have used tunnelling to hop through intermediate servers with SSH, but what I am asking is different here, and I don't know what it would be called. Is there a way to open a connection from A to B, which could in turn be used "in reverse" from machine B to run commands on A?

  • 2
    This looks like what you're after: unix.stackexchange.com/questions/46235 . Basically you want the -R option of forwarding (exposing a port on the dialling machine to the remote host)
    – zefixlluja
    Jan 27, 2020 at 14:33
  • Reading through the answers now, but looks like it does :) Thanks a lot @zefixlluja! Feel free to vote to close as duplicate. I will support the vote once I finish reading if that answers my question, or clarify otherwise.
    – Jonathan H
    Jan 27, 2020 at 14:38

1 Answer 1


The short answer is yes you can, the how is:

machine-A$ ssh -R [ip__or_name_of_B]

Then on B you can ssh to A with:

machine-B$ ssh -p2222  

This says the following:

  • On A create a tunnel on the remote side (-R), such that any traffic that goes to localhost ( on port 2222 should come back through the tunnel and be sent to localhost ( now on the local side) port 22

  • The B command simply says, ssh to localhost port 2222 which is the entrance to the tunnel.

  • thanks to you i understand with a simple command
    – jonathan
    May 28, 2020 at 20:37

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