A A
RSS

How to mount your drives over the internet using SSHFS

Mon, Mar 2, 2009

Tweet this!

How to mount your drive over the internet using SSHFS
By Jonathan DePrizio

Introduction
SSH, or Secure Shell, is a technology that has been used for many years as a replacement for telnet. It allows you to control a computer remotely, either through an intranet or over the internet, and all traffic is encrypted, meaning that your ISP, or anyone looking at the datastream, can’t tell what is being sent and recieved.

An add-on to SSH is sftp, or Secure File Transfer Protocol, which enables you to transfer files over the secure connection created by SSH. However, in order to do this you must use an sftp client, like gftp on Linux, or WinSCP on Windows. Since this method requires you to download a file in order to modify it, and then upload it again, it is hardly ideal in a situation where you want to use or modify remote files as if they are a part of your local drive.

SSHFS is a great program that allows you to mount a remote drive or directory, over any network (including the internet), and act as if those files are located on your local machine. This HowTo will explain the short and easy steps to do this.

The How-To:
First, on the remote machine (the one containing the drive or directories you wish to mount elsewhere):

1. Install sshd. This is included by default in most distrobutions of linux, but is available through package management if it is not. In debian-based systems, such as Ubuntu, use the following command:

sudo apt-get install openssh-server

1a. If you haven’t done so already, make sure you’ve forwareded port 22 on your router! To get your local IP address, run /sbin/ifconfig



2. This step is optional. You may want to create ssh-keys, so that you don’t have enter a password each time you mount the drive. This is particularly useful if you want to automount the drive using /etc/fstab.
There is a great howto on creating ssh keys located here.

3. Install SSHFS on the machine on which you want to mount the remote drive. Using apt, the command is:

sudo apt-get install sshfs

4. Mount the drive. This can be done one of two ways; the first being from the command line:

sshfs user@host:directory mountpoint

Where user@host is your username on the remote machine, and its IP address or URL; the directory is the directory you wish to mount (/home, for example); and mountpoint is the local directory you will use to contain the remote files (this directory must already exist, and can be created using the mkdir command).

Another option is to add a line to your fstab file, which will allow easier mounting, and mounting on startup. Append the following to /etc/fstab:

sshfs#user@host:directory mountpoint fuse user 0 0

The “user” argument allows the mount to be manipulated by users other than root. Some distrobutions may complain about a badly-formatted fstab on statup, but this is normal and will not harm your system.

Now you can mount your sshfs drive using

mount [mountpoint]
Further Information:

The SSHFS Homepage

Like this post?

No related posts.

5 Responses to “How to mount your drives over the internet using SSHFS”

  1. cosmo says:

    Nice article!

    And since you can’t use `umount`, because you’re not root when mounting with sshfs from the command line as a normal user, to unmount, use:

    $ fusermount -u mountpoint

  2. inoculos says:

    great how to.

    To unmount and disconnect use
    fusermount -u ~/mountpoint,

    from:
    https://help.ubuntu.com/community/SSHFS

  3. shomas says:

    With debian install, if you want to be able to access it as a user other then root, then you need to add your “username” to the group “fuse”.

  4. Samme says:

    Great guide, but I can’t get it to work the way I want.

    I’ve added the line to fstab, but it doesn’t mount at startup, and when I type mount test/ then it comes up this line asking for my passphrase, hmm…can someone guide my in the right direction?

    Obviously I want the remote share to mount at boot without me ever needing to do anything, just like a local filesystem.

    Thankful for any help!

  5. Anonymous Coward says:

    SSH requires some form of authentication, and leaving a plaintext password in e.g. /etc/fstab is a security risk.

    You can copy your SSH keys from $HOME/.ssh/ to the same location on the server to allow passwordless login, which in turn enables passwordless mounting of SSHFS without being a security risk.

Leave a Reply

Subscribe

Weekly Poll

Do you have a backup system?

View Results

Loading ... Loading ...
TechThrob News
  • Loyal visitors will notice that TechThrob is sporting a new layout, which will make it easier to find great content and see what people are saying about hot posts. Additionally, post tags and categories are being reorganized, which should make it even easier to find what you’re looking for. Thanks for reading, and I hope you’ve found useful stuff here. If so, I encourage you to subscribe to the RSS feed.

Related Posts

No related posts.

Search TechThrob

Categories

Archives