Series two, in a string if posts about SSH is sshfs. For those unaware, sshfs provides the ability to mount a remote SSH server as though it was a local device on your machine. But first, let me show you how to browse a SSH remote system using a GUI on the Gnome desktop.
If you go to the “Places” menu, and click on “Connect to Server…”, you will have a dialog that will allow you to connect through a variety of options, SSH being one of them. After entering in the address of the SSH server, the directory you want to mount and your username and name to call to connection, a folder will appear on your desktop that you can browse, as though they were folders on your machine itself. The problem with this method, however, is two-fold:
- First, the GUI folder that you see on your desktop for browsing the remote system is not “seen” through a number of applications. All KDE applications will not see the SSH folder. Also, many GTK applications will not see the folder. Gimp is one such application. Using File -> Open, I cannot browse to the SSH server.
- Second, many of the files and applications residing in the SSH folder do not behave as they would if they were locally stored files and applications. This includes editing text, viewing images, playing media and other things. In my experience, some of the files will behave as they should, others won’t. It’s very inconsistent.
Sshfs changes this. When you mount the SSH server to a local mount point on your local machine, then all applications, including KDE applications, have access to the files and folders. Also, browsing the mount point, you can edit and execute files just as if they resided locally on your machine. It’s really quite a pleasant experience.
So, lets get started then. How do we create an sshfs mount point, and how to we get the SSH server to look like locally stored files and directories? Easy. You can actually do it in 5 steps. Let’s go through them one by one:
First, obviously, we need the software. Using Ubuntu (or a Debian-based derivative as appropriate), pull up a terminal, and type:
sudo aptitude install sshfs
It will probably prompt you that dependencies need to be installed also, which is fine. The great thing, is sshfs is part of fuse, which has now been implemented as a module into the kernel. So, this tutorial is 10 easier, thanks to that, then it was 5 years ago.
Second, we need to create the mount point that we will use for the sshfs. Because you will be mounting the remote SSH server locally, I would suggest that you mount it as your normal user, not as root. As such, I would recommend the mount point residing in your ~ directory. For example:
You can name the directory whatever you would like. I chose sshfs, because it’s descriptive, and I won’t likely remove the directory later, when doing a system cleanup. Now that our mount point exists, we need to mount it. However, because sshfs uses fuse, we need to be part of the fuse group, which was just added when we installed the sshfs application. As such, in Ubuntu, let’s add our account to it:
sudo adduser aaron fuse
This would add the account ‘aaron’ to the group ‘fuse’. Make sure that ‘admin’ is also part of the list, or in Ubuntu, you lose your sudo privileges. Now that the account has been added, we need the environment variables to take effect. I only know of doing this through logging out and logging back in. Tedious, maybe, but necessary, and it only takes a couple seconds. That’s step #4.
Once logged back in, pull up your terminal again, and let’s finish this. The last thing to do is mount the SSH server to our mount point. A couple notes on this, before we type in the command. The options for sshfs are very similar to the options to the ssh command itself. This means you would pass a ‘-p’ flag and a port number if you have SSH on a different port. Also, as with ssh itself, you can use compression to keep the bandwidth on the wire minimal, which I would highly recommend. There are a number of other options that are available. See the man pages for a full description.
Also, you can mount any directory on the SSH server. I prefer to mount the root dir ‘/’, as I do a fair amount of system admin. Because I use compression on the wire, and because my SSH resides on a different port than 22, here would be the command that I would run to mount the server to my mount point:
sshfs -p 42224 -C user@server:/ ~/sshfs/
Again, you can mount any remote directory. If you don’t need to mount ‘/’, but ‘~’, that works all the same. Tailor that command to fit your needs. A suggestion would be, also, to put that command in an alias, so you don’t have to type that long string over and over. Something like:
alias mountsshfs='sshfs -p 42224 -C user@server:/ ~/sshfs/'
Now just run ‘mountsshfs’, and you’re set.
If you followed my tutorial on setting up SSH key authentication, including using the ssh-agent to manage your passphrase, then when you browse to the ~/sshfs/ directory, you shouldn’t be prompted for your key passphrase or your server password. As long as you did ‘ssh-add’ in the terminal before mounting the SSH server.