Reverse SSHFS

Mount a local folder on a remote machine.

This method uses ssh -R to open a reverse tunnel, and the remote machine has to have authorization to ssh back into the local machine. This may not be practical for all users, and if that is not acceptable for you, then this method may not be viable.

First, from the local machine:

ssh remote-machine -R 2222:localhost:22

2222:localhost:22 says "on the remote machine, open port 2222 to point back to 'localhost:22' from my vantage point, which is the ssh port back into the machine I'm ssh'ing from."

Then, on the remote machine within that ssh session:

sshfs -p 2222 localhost:local_folder remote_mount_folder -o uid=$(id -u),gid=$(id -g),allow_other

By default, if you try executing code files inside of the folder, you get a lot of strange "can't open file" errors, even when you try doing so as sudo. The uid=...,gid=...,allow_other sets the permissions such that your user temporarily "owns" the stuff that's mounted, and then other users are allowed to access data in the directory as well. This allows, for example, to run code out of that directory that then run by a less-privileged user.

I find this method very helpful when developing on a local codebase but executing/running on a remote server.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.