Mount Remote Directories Securely with SSH : Ubuntu

t me tell you, I’m a busy man. I’m always on the go and my trusty laptop is the only thing to keep me company much of the time. Despite being here, there and everywhere I still need access to my files and folders at home. But how can I access my files, securely, from anywhere on the planet? It is simple with SSH.

If you’re not familiar with SSH you’ll definitely want to check it out. SSH stands for Secure SHell and is probably one of the most used programs on the internet with its long list of uses. It is always encrypted, always secure and easy to use. I have long used it on a daily basis and here is how you can do the same.

You should have outgoing SSH access from a default Ubuntu machine. To check that you do try the following to a machine you have ssh access to: (do you have two machines on your network? On the remote machine make sure you’ve install ssh-server and then try):

ssh [user]@[machine]

Now that you know you can ssh you can also try to remotely mount a folder to your local machine. Before you’re able to do this you need to install a package to offer that support.

sudo aptitude install sshfs

sshfs stands for SSH file system. It’s a beauty. As mentioned it allows you to securely mount and access folders over the network or internet all day long. One of the packages that comes along with sshfs is something called fuse. You’ll need to load fuse as a kernel module before you can use it. You would do so using the following:

sudo modprobe fuse

You also might want to have fuse auto-load at boot time with the rest of your modules. You can use the following command to do so:

sudo sh -c “echo ‘fuse’ >> /etc/modules”

(Note: make sure you are careful to use the >> instead of a single >. >> appends the entry to the file, meaning it is added to the end. A single > simply writes the information to the file and could seriously screw up your system.)
At this point you have all of the tools necessary to mount a remote filesystem or folder on your machine. You just need a few pieces of information.

username (do you have access to the remote machine? if so, what username)
IP or hostname (what machine are you connecting to? works via name, domain or IP)
remote folder (what remote folder address do you want?)
local folder to use (where to you want to store the remote contents?)
An example of a command to mount a remote system, including the above peices, would be something like:

sshfs user@hostname:/path/to/folder /local/folder

If this doesn’t return any errors you should be able to then navigate to /local/folder and find your precious files there. When you are done, or you no longer need access to those files (for this session) you can safely “unconnect” using the umount command.

sudo umount /local/folder

Ooh, and one other option that you might find useful is to have this remote folder mounted automagically each time you boot your machine. Wouldn’t that be a nice feature. Well, …ok I’ll tell you.

The /etc/fstab file is a list of the boot-time auto-mounted filesystems or partitions. If you take a look at the file you’ll see your current setup. Normally your /, /swap, etc. You can add a new listing to the same file and have your remote folders automagically mounted via sshfs at each boot. Use something like:

[hostname/IP]:/path/to/folder /local/folder fuse defaults 0 0

Now that you’re more acquainted with SSH and sshfs why don’t you take ‘er for a spin. Enjoy.

Leave a Reply

Your email address will not be published. Required fields are marked *


− 3 = six