Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I'm trying to enter an sshfs mount in /etc/fstab with the following line:

sshfs#oli@192.168.0.2:/media/usb0 /media/ExtHD fuse     defaults,nonempty,allow_other 0 0

So that this volume is mounted at boot. After booting up, nothing happens, but when I use the command sudo mount -a, I am always prompted for the password. I have set up SSH Keys and transferred them over to the computer at 192.168.0.2, and can log in to regular ssh with no pasword. How can I stop fuse from asking for my password so that the volume can be automatically mounted at boot time?

If it helps at all, I am trying to connect to a home server running Debian from a laptop running Arch Linux. Thanks

share|improve this question

4 Answers 4

Key-based authentication can only work if the ssh process can find your key. You presumably have your key in your home directory; but you've never told sshfs where to look for a key. At boot time, it would be root mounting all filesystems, therefore the key must be either in /root/.ssh or referenced in /root/.ssh/config.

I recommend mounting the filesystem after you've logged in, and as your own user. Put this in a script that's executed when you log in:

ssh-add ~/.ssh/name_of_key.id_rsa
sshfs homeserver:/media/usb0 ~/exthd

Put an alias called homeserver in your ~/.ssh/config:

Host homeserver
HostName 192.168.0.2
User oli
share|improve this answer
    
Ahh, that is a better way of doing it, I didn't think to put it in my login script. Thanks! –  semiserious Jan 18 '12 at 17:19
    
Be careful using ~ in the mount point. If you're using a launcher icon on the panel to run the command instead of a terminal, the ~ may not be evaluated as /home/ and the command will fail. –  Nick Jan 11 at 18:47
    
@Nick If you're using a GUI, it might have a tool dedicated to automounting. If you follow my answer, you're to put the two commands in a shell script; the launcher icon would run that script. –  Gilles Jan 11 at 18:51

If you want it to boot without a password, you'll need to create a public/private ssh keys without password. It's not recommendend, but you can at least protect those files with a chmod 400 as root user.

After that, as usual, you'll need to copy the public key on the mount point :

ssh-copy-id -i my_new_key.pub oli@192.168.0.2

And you'll need to tell sshfs to use this key.

oli@192.168.0.2:/media/usb0 /media/ExtHD fuse     defaults,nonempty,allow_other,SSHOPT='IdentityFile /path/to/private/key' 0 0
share|improve this answer

I had the same problem.

I had previously setup ssh keys via the ssh-keygen and then ssh-copy-id -i ~/.ssh/id_rsa.pub root@192.168.0.100

ssh worked fine without asking me for a password so I was confused as to why sshfs still wanted the password...

That is to say,

ssh root@192.168.0.100 

worked fine, however sshfs still asked for a password when I typed

sudo sshfs root@192.168.0.100:/home/raspberry/Videos /home/pi/LinuxMintMountedFolder/ -o allow_other

As Gilles above explained, sshfs was looking in the root directory for the necessary keys.

Therefore, I solved this by just copying the files id_rsa and id_rsa.pub from my home folder's hidden .ssh folder to the root's .ssh folder i.e.

cp /home/pi/.ssh/id_rsa /root/.ssh/
cp /home/pi/.ssh/id_rsa.pub /root/.ssh/

Then, typing the following worked without bothering me for a password:

sudo sshfs root@192.168.0.100:/home/raspberry/Videos /home/pi/LinuxMintMountedFolder/ -o allow_other
share|improve this answer

I was able to make sshfs mount via fstab with Ubuntu 14.04 by doing using the following syntax as a standard user (note anything in CAPS is a variable for you to fill in):

USER@HOST:/REMOTE_DIR /LOCAL_DIR fuse.sshfs delay_connect,_netdev,user,idmap=user,transform_symlinks,identityfile=/home/USERNAME/.ssh/id_rsa,allow_other,default_permissions,uid=USER_ID,gid=USER_GID 0 0

This is a combination of the information found here http://superuser.com/questions/669287/automount-sshfs-using-fstab-without-mount-a and adding the delay_connect from here http://askubuntu.com/questions/326977/sshfs-is-not-mounting-automatically-at-boot-despite-etc-fstab-configuration.

I used this tutorial to get my USER_ID and USER_GID: https://kb.iu.edu/data/adwf.html

To find a user's UID or GID in Unix, use the id command. To find a specific user's UID, at the Unix prompt, enter:

id -u username

Replace username with the appropriate user's username. To find a user's GID, at the Unix prompt, enter:

id -g username

Also, if you want a full tutorial, it will be posted at http://www.variux.com/blog/?p=161

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.