I have a new post about SSHFS that highlights the latest operating systems, including MacOS. However, I’m leaving this post here for historical purposes.
At home I have what some may call a “back-office” server. Technically it’s in the laundry room, but it does all sorts of home automation type stuff: record TV, download files, store and play music, distribute files, run backups, etc. I may do a post on it later, but the gist is that it’s running Ubuntu Server with a bunch of disk drives.
Far and above, it’s main purpose in life is being a file server. There are several ways to connect to it: Samba (Windows file sharing), NFS (Unix Network File System). The server also runs SSH (Secure Shell) for terminal access – which can also be used a pass-through for secure local and remote file sharing.
The Advantage of SSHFS
Windows shares don’t have options to change ports, SSH does – and internet service providers often block Windows file sharing ports both for their own customers safety and to CYOA (cover your [their] own a$$) regarding file sharing. SSH, however, can be run on any port and it’s secure. I simply set up a firewall rule on my router (OpenWrt) to pass SSH traffic to my file server.
Why not use “the cloud?”
I firmly believe that by putting your files in “the cloud” (whether it be with Google, Apple, Amazon, Dropbox, etc.) you lose a little freedom. That doesn’t mean I don’t use any of those services, I just use them selectively. For the record Dropbox is a great service that works cross-platform and you’ll get some extra space if you sign up using this link.
Connecting with SSHFS in Linux
The simplest way to connect to another computers file-system using SSHFS is to do it through the UI using the Nautilus file manager. This is default file manager for several Linux distributions. In Ubuntu with Unity, click the folder icon in the launcher to bring a Nautilus window showing your home folder. From Nautilus you can click the file menu and choose Connect to Server…
Which will bring up a dialog where you can input the info for your SSH server. Change the Type drop-down to “SSH” and you’ll see all of these options:
Once you’ve connected, you’ll have a folder on the left side of Nautilus (under Network) that you can click on to browse files on the file server. You can right click the folder and choose Add Bookmark which will make it a breeze to connect to again and again:
You’ll notice I have two folders under “Bookmarks”: sshfs-Local and sshfs-Remote. I set up an additional connection for when I’m away from home which uses my outside IP and port I set up on my firewall/router.
Nautilus uses the GVFS FUSE (filesystem in userspace) module to mount the remote drive. To make it easy to access from the command line I created a symbolic link from ~/Documents/sshfs-Local-Documents to my SSHFS directory. All of the GVFS mounts (on Ubuntu 12.04 and earlier) can be found in your ~/.gvfs folder. Mine is linked as such:
justin@lappy64:~$ ls -l ~/Documents/sshfs-Local-Documents lrwxrwxrwx 1 justin justin 72 Oct 17 2011 /home/justin/Documents/sshfs-Local-Documents -> /home/justin/.gvfs/SFTP for justin on ghettivo/srv/home/justin/Documents
Starting with Ubuntu 12.10, the GVFS mounts are in /var/run/user. So my symlink in 12.10 looks like:
justin@lappy64:~$ ls -l ~/Documents/sshfs-Local-Documents lrwxrwxrwx 1 justin justin 82 Nov 1 09:44 /home/justin/Documents/sshfs-Local-Documents -> /var/run/user/justin/gvfs/sftp:host=ghettivo,user=justin/srv/home/justin/Documents
Connection with SSHFS in Windows
To connect to the same files using Windows, there’s Dokan SSHFS. I will say that at the moment this library is a little buggy, but it will work in a pinch. I get the feeling that it probably works better in 32-bit windows, but I don’t have any claims to back that up – I just know it’s a bit unstable in 64-bit windows.
Since Dokan is a .NET application, you’ll need to install a couple of things (maybe 3), slightly better than installing a Java application 😉
There’s a small chance that you have the latest “Redistributable Package” already on your Windows computer, so you can maybe skip it, but honestly it doesn’t hurt to install.
Once you’ve got everything installed you can run
DokanSSHFS.exe to connect to your SSHFS drive:
Happy (secure) file sharing!