Sunday, August 25, 2013

Using sshfs to set up a filesystem via ssh

I stumbled upon this because I wanted to use my Raspberry Pi as a media device. (There'll be a great post on some ways to do that but I haven't figured out how I want to do it and gotten it to work yet.) Basically, my raspberry pi doesn't have enough room for all of my media. (mainly just music is all I was working with) and all of my music is on another computer on the network. I tried setting up an ftp server on that computer, which will work, I just didn't like it very much. Eventually I found sshfs which was great for what I wanted to do.

To install sshfs if you don't already have it. - on ubuntu/similar.
sudo apt-get install sshfs

If you have used ssh or scp then sshfs should be pretty simple It's set up like this:
sshfs [user@]host:[dir] mountpoint [options]

So, lets say I'm logged into my raspberry pi, and I want, let's say to be able to access all of my music from my desktop computer through a folder in my home directory(on my raspberry pi). My desktop is named sigsauer.

From my raspberry pi:
mkdir ~/Music/
(if it doesn't already exist)
then,
sshfs sigsauer:Music/ ~/Music/
One thing I learned at this point, is that when you install new system you need to remember to keep you /etc/hosts file up-to-date. Because if you don't you might run into problems when trying to use the computer name. Once I got past that little hangup, then things started to work perfectly.
Now I could go into my Music folder which I just created and access all of the files as if they were local.
This has been great for me since I have 2 computers and a raspberry pi, that stay at home and are always on the same network, I don't like having my music library all over the place, adding music here and there then making a mess when I try to compile it. Now I have everything reading off and editing the same library, making it much easier to keep my library organized.
One of the computers has ubuntu server on it and I didn't feel like dealing with installing dropbox on it, so I simply added a command to my crontab to mount the dropbox folder from my desktop computer to my server computer. More about crontab here.
Keep in mind that to add it to the crontab, since it can't ask you for a password you need to have passwordless ssh authentication. I have a little bit of instruction about how to do that which I may have to turn into a new post, but I found the easiest way for me is to simply copy the whole ~/.ssh/ folder from one computer to the other, then delete any offending keys from ~/.ssh/known_hosts file.

Once you are done with sshfs and don't need access to the files anymore, you can unmount the directory by simply:
fusermount -u <mount_point>
so to unmount my Music -
fusermount -u ~/Music/

And now if you went into the folder it should be empty.

No comments:

Post a Comment