[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Can I mount a local directory to remote host?



On Thu, Nov 10, 2011 at 04:15:12PM +0800, Benimaur Gao wrote:
> I want to [...] mount the local dir to [the] remote host
> can i do such things behind NAT?

Darac Marjal <mailinglist@darac.org.uk> wrote:
> I shall assume you are trying to share a directory on A called /srv to a
> remote machine B as directory /mnt. This CANNOT be done from A. However,
> you should be able to connect to B and the mount A:/srv onto /mnt using
> SSHFS. In essense, then, B becomes the local machine and A is the remote
> one.

Possibly the complication that Benimaur Gao is concerned about, is that
it may not be possible to get from B to A. It seems to me that the extra
part of the solution here is to use the connection from A to B to build a
reverse ssh tunnel that allows B to get back to A. Then the sshfs mount
can be built.

I've not tried this level of complexity for quite a while, but I think
it would go something like this:

    hloc$ ssh -R localhost:10022:localhost:22 hrem
    hrem$ sudo sshfs localhost:/srv /mnt -p 10022

For purposes of illustration I've made the following assumptions:
 * "hloc" and "hrem" are names for the local and remote hosts
 * "/srv" is the directory to be mounted, and the mountpoint is "/mnt"
 * port 10022 is unused and available on hrem
 * the hostname is in the prompt to show on which host a command is run

How efficient (and therefore how usable) this is, is an entirely different
matter. You'll also find the connection breaks when you log out. This is
intentional, but there are options to ssh that keep a connection alive
so it's definitely not insurmountable.

It's also possible to merge these two commands in to a single command run
on hloc, but I figured you would want to see what was happening, first.

Chris


Reply to: