ssh is secure shell. It's the thing people use to access their terminals remotely. There is this other thing called fuse, filesystems in userspace. It lets you run filesystems without having to compile kernel support for the filesystem into it. Then there's this thing called sshfs which is a fuse filesystem that lets you mount your home folder using ssh.

The only cool thing about that of course is that your router probably has an ssh port forwarded anyways (well not necessarily, but google 'setting up ssh' or 'port forwarding' first if you plan on doing this) so it makes it easy to access your files from anywhere on the net.

There are straightforward howtos here and there but i encountered some weird little caveats on Ubuntu Hardy like having to change permissions for stuff. so i thought i'd give another shot at this howto business.

Again don't blame me if your computer eats your turtle, but do reply in the comments to let me know if the howto smells a little funky.

To set it up here's the steps

Install sshfs

$ sudo apt-get install sshfs

Add your user to the fuse group in order to run the fuse mounting app

$ sudo adduser $USER fuse

Give permission for regular users to mount sshfs shares

$ sudo nano /etc/fuse.conf
then uncomment the line user_allow_other, removing the # at the beginning of the line

Make sure that the fusermount and fuse.conf are in the fuse group

$ sudo chgrp fuse /bin/fusermount
$ sudo chgrp fuse /etc/fuse.conf


Next you need to run this command of the fusermount app itself. i think it sets the userid bit of it

$ sudo chmod 4755 /bin/fusermount

At this point logoff and log back on.

To actually mount the folder you use this command

$ sshfs -C -o allow_other -o follow_symlinks username@ssh-server-or-ip-address: /path/where/you're/mounting/the/folder

username would correspond to the name of the user on the sshserver
ssh-server-or-ip-address would correspond to just that.
/path/where/you're/mounting/the/folder also self explanatory

The -C is for compression. That's not strictly necessary.useful if you plan on accessing your sshserver over the net though
-o follow_symlinks is also not necessary, what that does is symlinks will show up as the actual file. so if you had a symlink that followed something outside of the home folder, it'll still show up as the file rather than just a dead symlink

look at man sshfs for other options

For example if ssh is running on a different port, there'd be a -p 1234
or if you want it to automatically reconnect once the connection lapses that's -o reconnect

One way of making it run on startup would be to just put it in the Sessions startup thingy in Gnome

System->Preferences->Sessions->Startup Programs->Add

Give it a name and paste in the command. Instead of just having sshfs, replace that with the full path of sshfs. so it'd be

/usr/bin/sshfs -C -o allow_other -o follow_symlinks username@ssh-server-or-ip-address: /path/where/you're/mounting/the/folder

edit: oh I forgot. There's another howto that's a dependency of the mount on startup feature. passwordless ssh logins. Normally when you mount it you have to enter the password in the ssh login in order to mount the home directory. well you need to give your login key to the ssh server in order to be able to run the command without a password. that way it can mount it on startup without having to put in a password, a necessity that you wouldn't otherwise be able to do on startup (or at least i don't know how to do it trivially)

On the machine you're running sshfs on run this command

$ ssh-keygen -t rsa

it'll save the key to .ssh/id_rsa.pub . you want to copy the contents of that file to machine that you're logging into, into it's .ssh/authorized_keys2 file

$ scp ~/.ssh/id_rsa.pub remoteuser@remotemachineiporaddress:id_rsa.pub
$ ssh remoteuser@remotemachineiporaddress
$ cat id_rsa.pub >> ~/.ssh/authorized_keys2 && rm id_rsa.pub


Once this is done you can ssh into the machine without entering a password and therefor you can mount sshfs shares on startup without having to enter a password.

anyways if you have port forwarding setup you can basically access your files anywhere with this. It is immensely awesome, and saying that it changed my life would not be overstatement. simple example is my music collection. I have almost 50gigs. I have an eeepc (talk for another post), with this i can access the whole collection and i didn't have to do much of anything to the server or the eeepc . it's pretty sweet.

3 comments:

Anonymous said...

Awesome and most comprehensive tutorial I could find. Effective and accurate on Ubuntu 8.10. The 'follow_symlinks' was throwing me off and kept me from using any of the others.

Christopher said...

thank you.

i didn't think i'd be getting a compliment on a howto written by me. I'm usually the one following the howto.

Cameron said...

Great how to.

One simplification that I can offer is to use the ssh-copy-id (install your public key in a remote machine’s authorized_keys) command to copy the ssh key to the remote server :

ssh-copy-id serverNameOrIpAddress

Cheers

Cameron