Mount Remote Directories Securely with SSH : Ubuntu (6.06.1 / 6.10)

By | 2007/01/02

Let 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.

  1. username (do you have access to the remote machine? if so, what username)
  2. IP or hostname (what machine are you connecting to? works via name, domain or IP)
  3. remote folder (what remote folder address do you want?)
  4. 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. You might also enjoy my previous post about Network File Systems.

You also might be interested in a post at the Ubuntu Blog on the same topic.

technorati tags:, , , ,

14 thoughts on “Mount Remote Directories Securely with SSH : Ubuntu (6.06.1 / 6.10)

  1. Stijn

    Or you can just use the (apparently underadvertised) ‘Places -> Connect to Server…’ function, fill in the details, and have a nice folder icon on your desktop…

  2. Cameron

    Another good tool to work with sshfs is libpam-ssh

    Once you have setup libpam-ssh, you login to your ubuntu desktop using your SSH passphrase, then any ssh connections (normal ones as well as sshfs ones) auto connect without having to re-enter the pass phrase.

  3. textshell

    you can unmount the sshfs using fusermount -u /local/folder
    instead of
    sudo umount /local/folder

    that way even users without sudo access can do it (and users with don’t need to type the password just to unmount it)
    if the system is setup right (fuse kernel module is loaded at system startup) sshfs can be used without any need for sudo (or root access)

  4. Gustav

    By the way when you install the sshfs package (on dapper), fusermount gets installed without execute permissions for the users.

    $ ls -l /usr/bin/fusermount
    -rwsr-xr– 1 root fuse 18328 2006-05-11 19:45 /usr/bin/fusermount

    I’ve also noticed that in order for the user to execute sshfs you need to add this user to the fuse group. I did this so that the uid mapping can be done correctly.

    $ sshfs hostname:/path/to/folder /local/folder -o idmap=user

    Great article.

  5. Pingback: Mounting Remote Shares Via SSH « A Conservative Techie

  6. Pingback: Blog de Sergi » Blog Archive » Montar unitats amb seguretat per ssh

  7. Pingback: Quality Indonesian Blogger » Blog Archive » Filesystem SSH di Ubuntu

  8. TuxGirl

    When using /etc/fstab for mounting, how are you giving username / password? I don’t see that in the tutorial (I might just need to read more carefully), and it seems like a potential issue.
    My assumption is that you would need to have ssh-keys set up in order to get that to work correctly, because otherwise, you would need to do a manual login, which would make it difficult to auto-mount (how would it ask for your username/password?).
    Can you do it using ssh keys that require a password? When do you give the password?
    ~TuxGirl

  9. Pingback: » What You Ought To Know About Securing SSH Ubuntu Tutorials : Breezy - Dapper - Edgy - Feisty

  10. Konse

    Let’s make it easier!!!

    http://wiki.ubuntuusers.de/FUSE/sshfs

    requirements:
    1. a line fuse in /etc/modules
    2. the package sshfs installed

    3. a line in /etc/fstab
    sshfs#username@yourserver:/pathonserver/ /yourmountdir fuse uid=1003,gid=100,umask=0,allow_other 0 0

    and now the best an easiest:
    4. a line in menu->system->settings->sessions->startup
    sshfs username@yourserver:/pathonserver/ /yourmountdir

    That’s awful -> with starting the session, there is a password-question and no need of terminals!!!!

  11. Pingback: Gobisoft Ltd » Blog Archive » The shared Network drive solution revisted

  12. natuk

    Thank you for this info. I tried Konse’s advice and although it generally works – it does not work during the first session. If I log off and on again it works fine. There is, however, an annoying message coming up saying the gnome cannot “grab the keyboard” and there may be malicious activity on the session – but the mount still work fine.

  13. mirka

    you might also want to try the consoleFISH at http://www.serfish.com -> a free web ssh client which can help you to greatly increase your mobility.

    just be aware of the security issues related to using web based server access: the mentioned site offers a good tutorial.

Comments are closed.