3

I'm trying to add portforwarding to my sshfs-mount-scripts:

sshfs tim@devserver1:/ /home/tim/mnt/devserver1/ 
-o SSHOPT=LocalForward 127.0.0.5:3306 127.0.0.1:3306

So far I've failed using the correct syntax. Using brackets or commas instead of spaces did not work.

2 Answers 2

6

Unfortunately, that is not possible with -o. The list of ssh options supported by sshfs can be found in the source code:

static const char *ssh_opts[] = {
        "AddressFamily",
        "BatchMode",
        "BindAddress",
        "ChallengeResponseAuthentication",
        "CheckHostIP",
        "Cipher",
        "Ciphers",
        "Compression",
        "CompressionLevel",
        "ConnectionAttempts",
        "ConnectTimeout",
        "ControlMaster",
        "ControlPath",
        "GlobalKnownHostsFile",
        "GSSAPIAuthentication",
        "GSSAPIDelegateCredentials",
        "HostbasedAuthentication",
        "HostKeyAlgorithms",
        "HostKeyAlias",
        "HostName",
        "IdentitiesOnly",
        "IdentityFile",
        "KbdInteractiveAuthentication",
        "KbdInteractiveDevices",
        "LocalCommand",
        "LogLevel",
        "MACs",
        "NoHostAuthenticationForLocalhost",
        "NumberOfPasswordPrompts",
        "PasswordAuthentication",
        "Port",
        "PreferredAuthentications",
        "ProxyCommand",
        "PubkeyAuthentication",
        "RekeyLimit",
        "RhostsRSAAuthentication",
        "RSAAuthentication",
        "ServerAliveCountMax",
        "ServerAliveInterval",
        "SmartcardDevice",
        "StrictHostKeyChecking",
        "TCPKeepAlive",
        "UsePrivilegedPort",
        "UserKnownHostsFile",
        "VerifyHostKeyDNS",
        NULL,
};

If it were supported, the syntax would be sshfs -o 'LocalForward=....'

In addition, sshfs passes the -oClearAllForwardings=yes option, so even the forwarding defined in ~/.ssh/config are not honoured.

Since sshfs supports passing a ssh_command, and allows additional arguments there, what you can do instead is:

CODE='
  for i do
    [ "$i" = -oClearAllForwardings=yes ] &&
      i="-oLocalForward=127.0.0.5:3306 127.0.0.1:3306"
    set -- "$@" "$i"
    shift
  done
  exec ssh "$@"
' sshfs -o ssh_command='/bin/sh -c eval\\ "$CODE" sh' user@host:/path mnt
1

just building on @Stéphane Chazelas answer sshfs passes the -oClearAllForwardings=yes option so any forwarding that is defined will not be honoured

so this behavior can be overwritten by passing -oClearAllForwarding=no instead, this can be done as follows

sshfs -o 'ssh_command=ssh -oClearAllForwardings=no' user@host:/path/to/remote/directory /path/to/local/directory

you can additionally pass the LocalForwarding option as follows:

sshfs -o 'ssh_command=ssh -oClearAllForwarding=no -L 3309:127.0.0.1:3309' user@host:/path/to/remote/directory /path/to/local/directory

shameless plug: I've written a script to simplify mounting with sshfs called sshmount it sets a few sane default options such as reconnect, ServerAliveInterval=15, sshfs_sync and sync_readdir based on my own experience with sshfs and a few tips i recently received and as of today it will also have an option -F to not clear all forwardings and an option -S to specify ssh options xD

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .