Oct
08
2010
sshfs behind a socks proxy aka write your own fstab script

I am using a socks proxy on my office. This of course isnt a bug but a feature!

I want to mount a remote folder on a server outside my office dmz over ssh. So i ‘ve looked up for ssfs that mount an ssh remote folder with fuse (userspace). The main problem is that sshfs doesnt support any proxy settings! Thats a bummer.

So is there a way ?

From the command line i can pass sshfs through proxychains. But how can i do this through fstab ?

The normal entry on fstab is something like this:

sshfs#username@example.com:/home/username/folder/ /home/username/remote/folder/ fuse user,reconnect,compression=yes,ssh_protocol=2 0 0

and from cli is something like this:


proxychains sshfs username@example.com:/home/username/folder/ /home/username/remote/folder/ -C -o reconnect,ssh_protocol=2

That problem gave me a morning headache and i postponed everything i should be doing till i solved it.

And i solved it !!!

I didnt know that the first column in /etc/fstab can be a program or a shell script.
Do you ?

I learned it today, and i am extremely happy to learn linux stuffs with the old transitional way:
try & error.

So the above headache resolved by this entry on fstab:


proxysshfs      /home/username/remote/folder/         fuse    user,noauto     0       0

and this script: /usr/local/bin/proxysshfs

#!/bin/bash
unset http_proxy ; unset https_proxy ;
proxychains sshfs username@example.com:/home/username/folder/ /home/username/remote/folder/ -C -o reconnect,ssh_protocol=2

So now, everytime i am writing something like this:


mount /home/username/remote/folder/

my proxysshfs script is set in motion and the result is to execute the above command and finally mount the remote folder over ssh through a proxy.

  1. Avatar di Giannis Stoilis Giannis Stoilis

    Friday, October 8, 2010 - 14:29:43

    > the first column in /etc/fstab can be a program or a shell script.

    I think I had a mental orgasm while reading this… Thank you!

  2. Avatar di Steve Webb Steve Webb

    Friday, October 8, 2010 - 17:19:46

    Add autofs to this and you’ve really got something here.

  3. Avatar di enterprise mdm enterprise mdm

    Tuesday, October 19, 2010 - 20:42:22

    some great and important stuff, thanks!

  4. Avatar di md md

    Wednesday, July 18, 2012 - 02:16:16

    Thanks