Subscribe to 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

| More
This article was originally written on 12/14/06 Tagged with: SysAdmin, Ubuntu, Ubuntu Tips & Tweaks

Daily Email Updates

You can get our how-to articles in your inbox each day for free. Just enter your name and email below:


Name:
Email:

Comments (26)

  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!


Leave a Comment




Leave your friendly comment here.

If you have a computer help question, click here to leave it on the forums instead.

Note: Your comment may not show up immediately on the site.

Our Friends
Getting Started


About How-To Geek
What Is That Process?
svchost.exe
jusched.exe
dwm.exe
ctfmon.exe
wmpnetwk.exe
wmpnscfg.exe
rundll32.exe
wfcrun32.exe
Ipoint.exe
Itype.exe
Wfica32.exe
Mobsync.exe
conhost.exe
Dpupdchk.exe Adobe_Updater.exe

Copyright © 2006-2009 HowToGeek.com. All Rights Reserved.