How to: Mount a SFTP Folder (SSH + FTP) on Ubuntu Linux using SSHFS & Fuse

Purpose: to mount a remote directory on my local Ubuntu Linux Desktop system using SFTP (which is SSH in an FTP-like fashion). The goal is to easily gain access to a remote system’s files through another folder on my desktop. I used sshfs to accomplish this.

Note: This post refers to version 6.10 of of Ubuntu — with later versions (e.g., Fiesty 7.10) you don’t need to take these steps. You can connect to SSHFS via the PLACES –> CONNECT TO SERVER menu option.

Special Thanks: goes to user llamakc from ubuntuforums.org for helping me with this one night in this thread; also, can find Ubuntu’s SSHFS documentation here.)

install the sshfs software and mount

After some trial and error on my part, I found that only a few simple steps are needed to get everything up and running:

First, get the sshfs software (which is based on FUSE); if you have Ubuntu, this is easy because it is an included package available for easy install. After the package is installed, you need to add your username to the fuse group. On Ubuntu, you would open a terminal window and perform the following:

  • $ sudo aptitude update
  • $ sudo apititude install sshfs
  • $ sudo adduser yourusername fuse

After, restart your machine. (I have tried just logging in and logging out, but I kept getting permissions errors — all of which disappeared after a restart.)

The next step it so to create an empty directory that will serve as the “window” into the SFTP server. I created a folder on my desktop called sftp. Once the folder has been created, simply run sshf using the appropriate login information (host username and IP), the host and local directories, and the SFTP connection is mounted on a folder on my desktop.

  • $ mkdir ~/Desktop/sftp
  • $ sshfs HOSTuser@remote.host.or.ip:/host/dir/to/mount ~/Desktop/sftp

This folder will work like any other folder on your system; when you restart your computer (or logout and log back in) you will have to go through the last step of the process again (calling the sshfs program) to enable the folder on your desktop (save time by creating a bash alias).

possible errors and workarounds

When I restarted my system the first time (using Ubuntu 6.06), after having so cleverly got sshfs to work, and tried to run my sshfs command I got an error:

  • $ sshfs HOSTuser@remote.host.or.ip:/host/dir/to/mount ~/Desktop/sftp
  • fusermount: failed to open /dev/fuse: No such file or directory

A quick search on google brought me to the sourceforge FAQ for sshfs and there, lo and behold, the following was suggested to rectify the situation:

  • $ sudo mknod -m 666 /dev/fuse c 10 229

After running this command, I was able to mount my SFTP directory. I never received this error using Ubuntu 6.10.

If you get any permission denied warnings, be sure you have added your username to the fuse group and also restarted your system.

create a bash alias to save time and typing

To save time, I created a bash alias that would remember all the details for me.

First, make make sure my system reads from the ~/.bash_aliases file (it may not be default). Open ~/.bashrc and ensure the following lines are uncommented:

  • # Alias definitions.
  • # You may want to put all your additions into a separate file like
  • # ~/.bash_aliases, instead of adding them here directly.
  • # See /usr/share/doc/bash-doc/examples in the bash-doc package.
  • if [ -f ~/.bash_aliases ]; then
  • . ~/.bash_aliases
  • fi

Next, create (or modify if you already have one) your ~/.bash_aliases file.

  • $ nano ~/.bash_aliases

I added the following single line of code to the document (first call the mknod, if you are getting the error, then the sshfs):

  • alias sftp='sudo mknod -m 666 /dev/fuse c 10 229; sshfs HOSTuser@remote.host.or.ip:/host/dir/to/mount ~/Desktop/sftp'

Now, when I open the terminal, I just type:

  • $ sftp

And everything loads correctly. Is very fast and very nice. I like it.

finally:

Changes to your ~/.bash_aliases file will only take effect after you have reopened the terminal or called:

  • $ . ~/.bash_aliases

If you ever want to unmount the directory without logging out or restarting, use the following:

  • $ fusermount -u ~/Desktop/sftp

4 Responses to “How to: Mount a SFTP Folder (SSH + FTP) on Ubuntu Linux using SSHFS & Fuse”


  1. 1 simtris

    You can do exactly teh same thin with the application in the menu shortcuts : ‘connect to serveur’.
    Just choose SSh, type your informations and here you have on you’r desktop the remote directory.
    It’s working but maybe your method is better, i’vs no ideas.

  2. 2 Damon

    Yes, you are correct! This post referred to an earlier version of Ubuntu — I have updated to include the note that this is for older versions and is no longer necessary. Thanks for reminding me.

  3. 3 Nick

    This is actually still helpful even though you can mount locations using the “connect to server” method now. Nautilus navigates the folder using “sftp://user@host” which not all programs can handle properly. Using the sshfs method allows you to mount it as a regular folder and all applications can work with it.

  4. 4 Damon

    Yea - I still use it … though with 08.04 you only need to run a sudo aptitude install sshfs and no longer have to monkey around with all those other steps. Can mount the file system right after that. I use it all the time still. Not a fan of Nautilus’s method …

Leave a Reply