SEARCH

How-To Geek

How to Mount a Remote Folder using SSH on Ubuntu

Connecting to a server across the internet is much more secure using SSH. There is a way that you can mount a folder on a remove server using the SSHFS service.

There are quite a few steps that you’ll have to follow, so get ready and open a terminal window.

First we’ll install the module:

sudo apt-get install sshfs

Now we will use the modprobe command to load it

sudo modprobe fuse

We’ll need to set up some permissions in order to access the utilities. Replace <username> with your username.

sudo adduser <username> fuse

sudo chown root:fuse /dev/fuse

sudo chmod +x /dev/fusermount

Since we’ve added ourselves to a user group, we need to logout and back in at this point before we continue.

Now we’ll create a directory to mount the remote folder in. I chose to create it in my home directory and call it remoteserv.

mkdir ~/remoteserv

Now we have the command to actually mount it. You’ll be prompted to save the server key and for your remote password.

sshfs <username>@<ipaddress>:/remotepath ~/remoteserv

Now you should be able to cd into the directory and start using it as if it was local.

geek@ubuntuServ:~/remoteserv$ ls -l
total 16
drwxr-xr-x 1 951247 155725 4096 2006-12-13 13:30 howtogeek.com
drwxr-sr-x 1 root root 4096 2006-09-11 06:45 logs
drwx—— 1 951247 155725 4096 2006-08-11 16:09 Maildir
drwxrwxr-x 1 951247 155725 4096 2006-10-29 02:34 scripts

Lowell Heddings, better known online as the How-To Geek, spends all his free time bringing you fresh geekery on a daily basis. You can follow him on if you'd like.

  • Published 12/14/06

Comments (33)

  1. BS News

    What’s the point of prefacing the commands with sudo? I’m not sure I understand that.

  2. Mike

    sudo chmod +x /dev/fusermount

    i think the line above was supposed to be this.

    sudo chmod +x /dev/fuse

  3. Kirk Badger

    Thanks for the usefull Ubuntu Linux how to’s

  4. The Geek

    sudo allows you to execute something in the context of the root user, and is usually used when performing system administration tasks.

  5. RobbieF

    It should be noted that the mount point must be within a folder that your user owns. so ~/remotesrv (or anything within your home folder ~) will do fine.

    I usually like to put all my mountpoints in /mnt, just ’cause I like having them all together; but with this method that will not work because you do not own /mnt (root does).

    Also, when you run the sshfs command, be sure to NOT use sudo; otherwise you’ll be mounting the filesystem as root; at which point you would not be allowed to access it, because you are not root.

    Thanks for the tutorial. I wanted to try mounting through SSH rather than SAMBA for convenience sake on one of my new Ubuntu servers; and this did the trick. Cheers.

  6. The Geek

    Robbie,

    Thanks for the commments… I’m glad it helped!

    I decided a while ago to switch to all secure connections, no more ftp, which is what prompted this article.

  7. Jonathan

    I had one problem with this HOW-TO. When I executed :

    sudo chmod +x /dev/fusermount

    said that /dev/fusermount didn’t exist, but the fusermount file is in /usr/bin, so I executed :

    sudo chmod +x /usr/bin/fusermount

    and it works fine now.

  8. MrDog

    This worked great for me and it opens up all sorts of possibilities. Could someone suggest the best settings to auto-mount in fstab?

  9. Mark

    I don’t think you want to use the fstab.

    I would suggest using rc.local to run the sshfs command.

    Be aware that you will be placing your username and password in plain text in your rc.local file. You may want to add some ssh certificates to prevent the need for a password.

  10. Rob

    Couldn’t get it to work at all..

    fusermount: failed to open /dev/fuse: Permission denied

  11. Matt

    This is great… I now have practically direct access to my files on my school account without going into the lab. Thanks! Linux blows my mind once again…

  12. Ellen

    @Mark:

    “I don’t think you want to use the fstab.
    I would suggest using rc.local to run the sshfs command.”

    could you please explain how to do that?

    thanks,
    /el

  13. JDaus

    thanks for the great tutorial … not using ubuntu … but it worked with modification here …

    Is there a way of mounting SSHFS within windows that anyone knows about ???

    cheers
    JD

  14. Mattis

    Totally sweet. Works like a charm, and the really neat thing is that the computer acting as server only needs SSH … Wonderful. Thanks for the tutorial.

    Rob:
    > Couldn’t get it to work at all..
    >
    > fusermount: failed to open /dev/fuse: Permission denied

    See the second comment, by Mike. Do that, and I think you’ll be fine.

  15. bart

    shonds great, i’ll try this on fedora, mabe even for my home dir…

    thanks@The Geek :0

  16. Morten

    You can use sftp to mount ftp-drives in windows.

  17. av

    It works. But How to unmount?

  18. Agustin

    Works fine, but I think there a little mistake.
    sudo chmod +wx /dev/fuse ?
    sudo chmod +x /usr/bin/fusermount ?

  19. bansidhar

    I installed it on Fedora 7. Required me only the following steps.

    #yum install sshfs
    #modprobe fuse
    #sshfs -o allow_other @:/remotepath ~/remoteserv

    I did su before installing because I cannot sudo
    This works like a charm for me

  20. bansidhar

    in my previons comment please read the line

    #sshfs -o allow_other @:/remotepath ~/remoteserv

    as

    #sshfs -o allow_other username@ipaddress:/remotepath ~/remoteserv

  21. Walter

    All:

    The line:

    sudo chmod +x /dev/fusermount

    should probably be

    sudo chmod +x /dev/fuse

    and NOT:

    sudo chmod +x /usr/bin/fusermount

    as some others have suggested. The latter suggestion is meaningless, since /usr/bin/fusermount is already executable by default, and the command makes the file “fusermount” executable, which it already is. Furthermore the prior command is to do with setting up /dev/fuse so it makes perfect sense that the chmod is a continuation of this. BTW, with the above correction, this howto works fine for me.

  22. Walter

    To unmount, use:

    fusermount -u /path/to/local/mountpoint

    You would’ve seen this had you read the manual, using:

    man sshfs

  23. yungchin

    Thanks for this.
    Actually, on my Ubuntu 8.04 system I found that sshfs was already installed, and the fuse module was already loaded (and I don’t have NTFS partitions?!). Even the group membership was already properly configured!
    Nonetheless, a useful walk-through!

  24. thegreedyturtle

    This is incredibly useful for someone that works on multiple linux servers. Ideally though, I’d like to lock the folder, preferably with a gksu type login, although since it’s set to be under my own user, it wouldn’t work quite like that.

    I’m also wondering if i have this mounted in an area that is indexed, will I be able to search within the mounted folders with my own machine?

  25. Alek_86

    Linux … never sieze to amaze you!

    My boss is so happy cause I use this helpful sshfs to cut down time for transfering from an old server to newone! :D

    Thanks a lot! ;)

  26. Spudley

    Ah, this is very useful.

    I’ve been using KDE’s fish:// protocol to achieve the same result, which is really excellent, but was causing me a few problems — I needed to use SVN in the remote folders, and I wanted to use KDE’s other wonderful plugin, kdesvn, but you can’t combine kdesvn with fish.

    The good news is that I can combine kdesvn with sshfs, so thanks to this article I can now manage my SVN area. Yay!

  27. Dan

    Superb – thought i’d add a note for those that use non standard ports, the port flag is -p and is used when mounting as follows:

    sshfs -p PORTNUMBER @:/remotepath ~/remoteserv

  28. PolArise

    It seems that the location of fusermount varies. You have to find it with:

    which fusermount

    then you can

    sudo chmod +x

  29. Justin Smith

    Thanks for the tip!

    A heads up for Ubuntu 10.4.
    I did not have to do any of the work with fuse to get this working.

    all i did was:

    sudo apt-get install sshfs
    sshfs @:/remotepath ~/remoteserv

    And it worked like a charm.

    Thanks again!

  30. Milan

    Works fine for mounting the first time,
    but when I reboot the system, it just keeps the ~/remoteserv folder but it is not linked anymore ?

    any suggestions ?

    Using Ubuntu 10.4

  31. Wayne

    Check the version of your fuse. You need at least version 2.4 to make it mount at boot time.
    run sshfs -V to see the version numbers.

    It is a somewhat tedious task, but here: http://ubuntuforums.org/showthread.php?t=430312

  32. Daniel G.

    Not working….
    Remote box: CentOS 4.9 2.6.9-89.35.1.EL #1
    Local box: Linux Mint 10 Julia 2.6.35-22-generic #35-Ubuntu SMP

    When I run sshfs root@192.168.0.200:/var/www/html ~/remoteserv I get
    read: Connection reset by peer

    what gives?

  33. spufidoo

    Sweet! Needed access to my home drive – all I had was a Windows XP laptop and my trusty Linux Mint USB key… Booted into Mint, clickety clickety click… Tadaa!
    Thanks!

Enter Your Email Here to Get Access for Free:

Go check your email!