To mount a directory via sshfs in fstab, I found no instruction that worked for me on an ubuntu 8.04 installation.
I have created a user which is allowed to log in only via sftp to my server, and I now wanted a directory on the server being visible readonly on my client, mounted over sftp to maintain ease of configuration and high security. Fuzzing around with smbfs, nfs or something else seemed like a bad idea as I want the same solution to work also over internet, where the only entrance hole through my server is via ssh anyway.
Setup the server so it is possible to sftp to it. See my previous post. I call this user romusic. The server is at 192.168.0.10 below. I carry out commands in a root shell (typing sudo is not my thing, really) by issuing "sudo su - " in the beginning.
Setup passwordless ssh login (see any of the million posts on this if you need more info).
$ssh-keygen
Copy the contents of the generated .pub key into ~/.ssh/authorized_keys on the server. Copy the private key to /root/id_rsa_romusic
make sure sshfs works as a user (using a password here)
$sshfs romusic@192.168.0.10:musik/ musik/
To be able to pass the identity file to ssh via sshfs we have to make a wrapper. This step is what is not covered in the posts I found on the subject. That is because I could not pass "ssh -i id_rsa" as ssh executable to sshfs, this made it complain over execvp. Here is the workaround:
Create the file /root/ssh_i_romusic.sh
#!/bin/sh
/usr/bin/ssh -c arcfour -i /root/id_rsa_romusic $@
Note that I also use cipher arcfour to speed things up here, this should be avoided unless you trust your network somewhat. Just leave it out if you do not know what it means or if you are on a potentially untrusted network.
Do not forget to set that file owned by root:root and it is executable and not writable.
Create a mount point
$mkdir /mnt/musik
Make sure you can mount (this is also needed to accept the key id, needed only once)
$sshfs romusic@192.168.0.10:musik/ /mnt/musik/ -o allow_other,uid=0,gid=0,reconnect,umask=222,sshfs_debug,sshfs_debug,"ssh_command=/root/ssh_i_romusic.sh"
I accepted the key and everything went fine. I now umount and then head for /etc/fstab to make it mount automagically.
$fusermount -u -z /mnt/musik
my fstab entry:
sshfs#romusic@192.168.0.10:musik/ /mnt/musik/ fuse ro,allow_other,uid=0,gid=0,reconnect,umask=222,sshfs_debug,sshfs_debug,ssh_command=/root/ssh_i_romusic.sh 0 0
Make sure everything works by
mount -a
and see there are no complaints.
After that, /mnt/musik should be readable.