How to mount remote SSHFS via intermediate machine? Tunneling?

29,753

Solution 1

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.

Solution 2

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...

Solution 3

This is what works for me on HighSierra 10.13.6, SHFS version 2.5 (OSXFUSE SSHFS 2.5.0) OSXFUSE 3.10.4. FUSE library version: 2.9.7

Based on Rodrigo Farias's answer above + clemisch and Ohad Rubin comments for noting the -J option:

sshfs -p port finalserver_username@finalserver:/path/to/folder/on/finalserver/ /local/mount/point -o ssh_command='ssh -J intermediate_server_username@intermediate_server:port'
Share:
29,753

Related videos on Youtube

Andrei
Author by

Andrei

Updated on September 17, 2022

Comments

  • Andrei
    Andrei over 1 year

    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?

    Update

    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 [email protected]:/myremotepath /mylocalpath
    

    Is it correct?

    How do I destroy the tunnel when I am done?

    • edk
      edk almost 14 years
      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
  • Andrei
    Andrei almost 14 years
    Is the following command the right way to do that? ssh -f user@machineB -L 25:machineA:25 -N
  • edk
    edk almost 14 years
    yes if you have sshd listening to port 25 on machine A. then you'll just have to sshfs -p 25 [email protected]:/path /localpath
  • Andrei
    Andrei almost 14 years
    Aha, so for default ssh setup I need ssh -f user@machineB -L 22:machineA:22 -N, right?
  • Ohad Rubin
    Ohad Rubin almost 6 years
    With the new -J option in Openssh 1.1 it is something along: sshfs ma: /mnt -o ssh_command='ssh -J mb'
  • clemisch
    clemisch almost 5 years
    Does this have any benefit vs. using only -o ssh_command="ssh -J machineB" ?
  • somebadhat
    somebadhat about 4 years
    If it works for you why do you have to base it on answers and comments?
  • dcneuro
    dcneuro about 4 years
    I'm not sure what you mean. The -t options worked on a previous setup, but not on this one. That's what I meant by "works for me on ..". The answer is a combination of the original answer by Rodrigo with the comments from Ohad and Clemisch, hence the attribution.
  • MRule
    MRule over 3 years
    I wasn't able to get this syntax to work on my particular network configuration, but the -o proxyjump syntax did.
  • The Doctor
    The Doctor about 3 years
    Thanks! This was the only solution that worked for me in Catalina.
  • gview
    gview about 3 years
    Currently using an old mb pro with Mojave. Used macports to install sshfs. Was able to connect to a server in a VPC going through a gateway box using this method. Thanks!