Search code examples
macosubuntusshsshfs

Mount a local directory (Mac) on a remote machine (Ubuntu)


I know we can use sshfs to mount a remote machine directory on a local machine, but, Is the reverse possible. I want to edit the files on my local system and do not want them to reside permanently on the remote server.

I tried this (https://github.com/agirorn/mount-on) doesn't seem to work.

I would like to mount a local directory like:

/Users/username/sshfs_share_folder

onto a remote machine which I have ssh access to, such as:

/home/username/shared_folder

Solution

  • Assuming the local machine is behind a NAT and cannot directly ssh to local machine from remote machine, run a reverse ssh tunnel on the local machine using remote port forwarding.

    # on local machine
    ssh -R 2222:localhost:22 <remote-user>@<remote-addr>
    

    Now, on the remote machine , you can use sshfs to mount a dir from the local machine by pointing it to localhost:2222 which internally tunnels the request to the local machine at port 22.

    # on remote machine
    sshfs -p 2222 <local-user>@localhost:<local-dir> <remote-dir>