2

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.

5

This was easier than I thought!

All one has to do is bind the port 2048 of serverC to a port on pcA. For simplicity I use the same port number 2048:

user@pcA $ ssh -L 2048:localhost:2048 user@serverC

One needs to keep this terminal window open.

Then, mounting the directory pcB:/home/user locally on pcA looks like this:

sshfs -o port=2048 user@localhost:/home/user/ /mnt/pcB

Nice side-effect: This means you can also use efficient X-server connections, e.g. freeNX or vnc to retrieve a display of pcB. Just connect to localhost:2048 and use the correct credentials (user name/password) for machine pcB!

If you don't want to have to keep a terminal open for the connection, you use:

ssh -NfL 2048:localhost:2048 user@serverC

Note that doing this might violate your employers'/organizational security policy, so make sure to get appropriate permissions.

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.