This is an extension of the question by @Andrei
How to mount remote SSHFS via intermediate machine? Tunneling?
I'm in the same situation that I want to mount a remote directory, however the difference is that both machines A
and B
are not publicly exposed on the internet. A
is my local work station.
So I can neither ssh from A -> B
, nor B -> A
.
What I regularly do, is establish a reverse connection from B -> C
, where C
is a rented virtual server (VPS). A script doing this connection (and reconnecting in case of lost connection) is started via the @reboot
key of cron
.
user@pcB $ ssh -R 2048:localhost:22 -p<port> user@serverC
Then, to go from A -> B
I take the intermediate route A -> C -> B
.
user@pcA $ ssh serverC
user@serverC $ ssh -p 2048 user@localhost
user@pcB $ # okay, logged in.
I'm looking for a way to mount the directory pcB:/home/user
on pcA
.
How do I connect to a pc through another pc using ssh is similar, but the solutions provided don't work in this scenario: the connection map in my case is A -> C <- B
not A -> C -> B
.
Best Answer
This was easier than I thought!
All one has to do is bind the port
2048
ofserverC
to a port onpcA
. For simplicity I use the same port number2048
:One needs to keep this terminal window open.
Then, mounting the directory
pcB:/home/user
locally onpcA
looks like this:Nice side-effect: This means you can also use efficient X-server connections, e.g.
freeNX
orvnc
to retrieve a display ofpcB
. Just connect tolocalhost:2048
and use the correct credentials (user name/password) for machinepcB
!If you don't want to have to keep a terminal open for the connection, you use:
Note that doing this might violate your employers'/organizational security policy, so make sure to get appropriate permissions.