Основываясь на другом подобном вопросе, я нашел решение. Это потребовало серьезных экспериментов и настройки. Обратите внимание, что этот измененный скрипт теперь несовместим с монтированием из /etc/fstab
.
/etc/auto.master
/- /etc/auto.sshfs uid=1000,gid=1000,--timeout=30,--ghost
/etc/auto.sshfs
/local/mountpoint -fstype=fuse,rw,nodev,nonempty,noatime,allow_other,workaround=rename,ssh_command=/usr/local/sbin/ssh_user :sshfs\#remoteuser@server\:/remote/path
Конечно, это должен быть исполняемый файл: /usr/local/sbin/ssh_user
#!/bin/bash
# declare arrays for ssh options
declare -a ADD_OPTIONS
declare -a CLEANED_SSH_OPTS
# add options to be automatically added to the ssh command here.
# example
#ADD_OPTIONS=( '-C' )
# empty default
ADD_OPTIONS=( )
# The following options to SSH cause it to open a connection and immediately
# become a background task. This allow this script to open a local socket
# for future invocations of ssh. (use "ControlMaster auto" in ~/.ssh/config)
SOCKET_OPTIONS=( '-fN' )
for OPT in "$@"; do
# Add list of values to be removed from sshfs ssh options. By default, sshfs
# disables X11 forwarding. We're overriding that behavior.
case $OPT in
"-x")
# this and these like this will be removed
;;
"-a")
;;
"-oClearAllForwardings=yes")
;;
*)
# These are ok.. add
NUM=${#CLEANED_SSH_OPTS[@]}
CLEANED_SSH_OPTS[$NUM]="$OPT"
;;
esac
done
# For some reason, I needed to generate strings of the ssh command before
# passing it on as an argument to the 'su' command. It simply would not
# work otherwise.
# Throwing the $SOCKET_OPTIONS in with the rest of the arguments is kind
# of hackish, but it seems to handily override any other specified behavior.
# Establishes an ssh socket if none exists...
SSH_SOCKET_CMD="ssh $SOCKET_OPTIONS ${ADD_OPTIONS[@]} ${CLEANED_SSH_OPTS[@]}"
su localuser -c "$SSH_SOCKET_CMD"
# ...and use that socket to mount the remote host
SSH_SSHFS_CMD="ssh ${ADD_OPTIONS[@]} ${CLEANED_SSH_OPTS[@]}"
exec su localuser -c "$SSH_SSHFS_CMD"
И, в случае, если кому-то все равно: ~/.ssh/config
Host *
ControlMaster auto
ControlPath /tmp/%u@%l→%r@%h:%p
ServerAliveInterval 10
Compression yes
Host host1 host1.myschool.edu host2 host2.myschool.edu
ForwardX11 yes
Ciphers arcfour256,arcfour128,arcfour,blowfish-cbc
Host host3 host3.myschool.edu
ForwardX11 no
Ciphers arcfour256,arcfour128,arcfour,blowfish-cbc