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. Debina/Ubuntu allows you to easily mount SSH folders via the GUI, however, these mounts won’t show up in the terminal (and in some programs). I used sshfs to accomplish this.

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 aptitude 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 sshfs 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 (thanks to El Pato for the naming suggestions).

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 dt-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 (of course, you can name it whatever you want):

  • dt-sftp

And everything loads correctly. Is very fast and very nice. I like it. Changes to your ~/.bash_aliases file will only take effect after you have reopened the terminal or called:

  • . ~/.bash_aliases

finally:

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

  • fusermount -u ~/Desktop/sftp

30 Comments (newest first)

  1. El Pato says:

    Since the SSHFS howto’s comments are closed, I shall post these 2 comments here.

    There is a typo in aptitude in the following line:
    sudo apititude install sshfs

    Also, making an alias called “sftp” is a bad idea as it conflicts with the actual sftp command. I suggest to use something like “sftpMount”, “mntSftp” or “supercalifragilisticexpialidocious” instead.

    • Damon says:

      Thanks for the typo and naming suggestion – it’s been a while since I had written that post and, for the most part, I was getting spam. Smile. Thanks again!

  2. Jonas August says:

    It worked for me without even rebooting or logging out (which I haven’t tried yet, gulp) on Ubuntu 11.04 on amd64.

    Thanks!

  3. Steve says:

    Great tutorial, thanks a lot. Been struggling with a few other tutorials, but this one worked first time!

  4. [...] Ssh Mounts Installation Tips [...]

  5. g says:

    what’s that command mean??

    [quote]mknod -m 666 /dev/fuse c 10 229[/quote]

    I dunno what the number meaning, and the ‘c’ letter… very interesting! I wanna try it out!

    • Damon says:

      You know, to be honest, it’s been so long since I had to use that command (that is, it works out-of-the-box for me now) I don’t remember. Smile.

    • AI0867 says:

      > mknod -m 666 /dev/fuse c 10 229

      You’re creating a device file to communicate with the kernel.
      > -m 666
      Permissions 666 (rw for everyone)
      > c
      Character device (other option is block device, which is mainly used for disks)
      > 10 229
      The major and minor device numbers. These are used by the kernel to identify which driver you want to talk to.

  6. [...] Kamil Kisiel Theoretically, yes. You can mount the remote filesystem on your local machine using FUSE. Then you can run a local copy of rsync between the mounted directory and the local directory. [...]

  7. Ubuntu Guy says:

    Thanks for this. I knew there had to be an easier way to ssh into something.

  8. Seth says:

    thank you i am a network admin and this has aloud me to use notepad++ running under wine to edit files on the server. btw have to do that often when customers mess up there web site lol. lots of remote work in the middle of the night thank man was a real life saver.

  9. I’ve seen this guide for mounting an SFTP directory, and I’ve learnt from a lot of tutorials as this one. Here my compendium for optimal configuration in both clients and servers:

    http://wiki.lapipaplena.org/index.php/How_to_mount_SFTP_accesses

    (special care of users and permissions)

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

    source http://blog.damontimm.com/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…

  11. Robin says:

    Awesome! Thank you very much for this. Makes working with a 10 year old laptop that much easier. :)

  12. Sheely says:

    Fucking love you, this works amazingly!! Saved me a lot of hassle, thank you!

  13. [...] Remote Connetions benutzen kann. Nach ein wenig googeln, habe ich dann eine Lösung gefunden und einen passenden Artikel wie man sshfs einrichtet dazu.Man muss einfach sshfs benutzen und kann so eine SSH Verbindung einfach auf einen Ordner [...]

  14. Carlos says:

    It is usefull for Xubuntu users !!.

    Thanks.

    Carlos

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

  16. Johs says:

    I really like your easy-to-walk-through article on sshfs. Many young GUI-*nixers could learn from you. Nice article!

  17. Damon says:

    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 …

  18. Damon says:

    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.

  19. simtris says:

    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.

  20. Nick says:

    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.

  21. manu says:

    Great
    You can add a -o follow_symlinks to include the symbolic links in the file systems

  22. Damon says:

    Could you show me a screenshot ? Did you have the font size increased ? And was it all the text or just the text in the “Code Snippets” ? What version of FF ?

    I don’t see what you are talking about right now … but will look into it if you can show me what you see.

    Thanks for the heads up.

  23. James says:

    The above comment is spam.. Search for “Hi there just wanted to give you a quick heads up. The text in your article seem to be running off the screen in Firefox. I’m not sure if this is a format issue or something to” within google, you will see what I mean..

  24. Damon says:

    Heh – thanks for pointing that out. Smile. Seemed innocent enough. Appreciate it.