I would like to mount a remote file system (A) using SSHFS, but sometimes I have IP address, access from which is not allowed. So my plan is to access it via another machine (B) in that network. Do I need to mount A on B and then to mount B (and A) on my local computer? Is there a better way to do it?


Just to clarify the procedure:

First, I make a tunnel

ssh -f user@machineB -L MYPORT:machineA:22 -N

And then I mount the remote file system

sshfs -p MYPORT user@ /mylocalpath

Is it correct?

How do I destroy the tunnel when I am done?

  • 1
    better way to set up tunnel is to have connection to B from GNU screen window using ssh user@machineB -L 2222:machineA:22 -N so you can easily kill it with ^C – edk May 9 '10 at 16:03

yeah tunneling. You connect machine B, create local tunnel (-L) to SSHd port of machine A then sshfs to localhost to the port of newly created tunnel.

  • Is the following command the right way to do that? ssh -f user@machineB -L 25:machineA:25 -N – Andrei May 8 '10 at 14:00
  • 1
    yes if you have sshd listening to port 25 on machine A. then you'll just have to sshfs -p 25 user@ /localpath – edk May 8 '10 at 14:20
  • 1
    Aha, so for default ssh setup I need ssh -f user@machineB -L 22:machineA:22 -N, right? – Andrei May 8 '10 at 15:32

You can use option ssh_command of sshfs to do the trick:

sshfs ma: /mnt -o ssh_command='ssh -t mb ssh'

Unmount with the usual

fusermount -u /mnt

Sorry this is 7 years late...

  • 2
    With the new -J option in Openssh 1.1 it is something along: sshfs ma: /mnt -o ssh_command='ssh -J mb' – Ohad Rubin Jul 18 '18 at 1:25

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.