Mounting filesystems over SSH with Ubuntu
June 30th, 2006
A great adition to Linux has been the filesystem in user-space project FUSE which brings us SSHFS. One now has the ability to mount remote filesystems through ssh. Installing sshfs is easy with a simple sudo apt-get install sshfs.
First one must add their user name to the fuse group either via the gui or the command line tool adduser. (As pointed out by Casey you need to logout-login for the group changes to take effect.) Next one needs to insert the fuse module into the kernel with a
sudo modprobe fuse
This module should be appended to the end of /etc/modules inorder for it to load when the system boots. Then it is possible to mount filesytems over ssh with a simple
sshfs username@sshserver: /media/directory
and then enter your password when prompted. This will automatically mount the users home directory. To mount a specific directory use
sshfs username@sshserver:/directory /media/directory.
Though most of us don’t want to open up a command line and go through this hassle everytime we want to mount our remote filesystem. For this I purpose the following solution. First we create a password-less login by setting up a trust realtionship with public keys. On the local computer in your home directory run
ssh-keygen -t rsa
When prompted for the location to save the file and a passphrase simply hit enter. The keys will be stored in $HOME/.ssh/id_rsa. The next step is to copy the public keys over to the remote server which has already been mounted in /mount/directory.
cat ~/.ssh/id_rsa.pub >> /media/directory/.ssh/authorized_keys
chmod 600 /media/directory/.ssh/authorized_keys
Now we can ssh into our remote box without the need for a password. The other problem one runs into with implementing a clean graphical sshfs experience is the fact that if one wants to unomunt the filesystem they can not simple right click unmount the system from the Gnome desktop icon. This is because umount requires root privlages, however fuse has a solution for this which is fusermount -u /media/directory. The following bash script can be attached to a menu or panel icon to do the simple mounting of the system and the unmounting if it is already mounted.
#!/bin/bash
if grep -q sshserver /proc/mounts
then fusermount -u /media/directory
else sshfs username@sshserver: /media/directory
fi
Don’t forget to replace sshserver, username, and directory with the appropriate values for your situation.
Entry Filed under: Ubuntu
3 Comments Add your own
1. Marc | July 5th, 2006 at 6:39 pm
I love sshfs and FUSE! Too bad it doesn’t work on FreeBSD 4.
2. Casey Watson | July 6th, 2006 at 11:44 pm
In Dapper, I added my user to the fuse group. I then ran sshfs casedog@casedogdesigns.com: casedogdesigns as the non-root user, I get the following error
fuse: failed to exec fusermount: Permission denied
I can mount fine if I run the command as root. Does the fusermount executable need to be suid root? Any suggestions?
3. Casey Watson | July 6th, 2006 at 11:49 pm
Apparently, you just need to logout for the group changes to take effect.
Leave a Comment
Some HTML allowed:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>
Trackback this post | Subscribe to the comments via RSS Feed