This will vary depending on the OS of the server you are connecting to. For centOS 5 you would add to the sshfs mount options:
-o sftp_server="/usr/bin/sudo /usr/libexec/openssh/sftp-server"
For Ubuntu 9.10 (I think, might be 9.04, but it's probably the same for both) or Debian you would add:
-o sftp_server="/usr/bin/sudo /usr/lib/openssh/sftp-server"
.
To find an the correct path for other systems running openSSH run
sudo grep Subsystem /etc/ssh/sshd_config
and look for the location of the sftp-server binary.
You might need to setup sudo with NOPASS:{path to sftp-server} or prevalidate with ssh user@host sudo -v
so that sudo
has a updated timestamp for notty
. In my case, my two commands were:
ssh login_user@host sudo -v
sshfs login_user@host:remote_path local_path -o sftp_server="/usr/bin/sudo -u as_user /usr/lib/ssh/sftp-server"
You probably want to add the _netdev
option to delay mounting until the network has been enabled:
sshfs#root@10.0.0.200:/home/ /home/ fuse transform_symlinks,allow_other,_netdev,nonempty,hard_remove 0 0
You can also put your script in /etc/network/if-up.d/
or the mount command in /etc/rc.local
.
Best Answer
The best solution would be
ssh-agent
as Zoredache suggests.Another is to put your key in
~/.ssh/id_rsa
, that way it will be detected automatically. (Useid_dsa
for DSA keys.)Yet another is
~/.ssh/config
. Put something like this in it (see manual page ofssh_config
for further details)