Mount a Remote Folder using SSH on Ubuntu

Sponsored Link
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.sshfs is a filesystem client based on the SSH File Transfer Protocol. Since most SSH servers already support this protocol it is very easy to set up: i.e. on the server side there's nothing to do. On the client side mounting the filesystem is as easy as logging into the server with ssh.

sshfs is based on FUSE (userspace filesystem framework for Linux), thus you will have to prepare fuse kernel module to be able to use it.

Install sshfs in Ubuntu

sudo apt-get install sshfs

This will complete the installation part.

Now we will use the modprobe command to load it

sudo modprobe fuse

Now you need to set up some permissions in order to access the utilities. Replace with your username.

sudo adduser 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

In the above command you need to replace usename and ipaddress.

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

user@testserver:~/remoteserv$ ls -l
total 16
drwxr-xr-x 1 951247 155725 4096 2006-16-13 13:03 Music
drwxr-sr-x 1 root root 4096 2006-10-11 06:05 logs
drwx—— 1 951247 155725 4096 2006-02-11 16:19 Documents
drwxrwxr-x 1 951247 155725 4096 2006-10-09 02:43 scripts

Sponsored Link

You may also like...

19 Responses

  1. Jan says:

    Hi, thx for the guide, however I have some questions, where you say “replace with your username”, do you mean to replace fuse with “yourusername”, and should it be the username of the ssh server?
    Another question about the ip adress, shoud it be from your pc, or from the ssh server?

  2. admin says:

    jan you need to replace username and ipaddress of ssh server

  3. kubaroz says:

    instead of

    sudo chmod +x /dev/fusermount

    you should change permissions of another file:

    sudo chmod +x /usr/bin/fusermount

  4. Stan says:

    Can you connect to Ubuntu via sshfs using the x-windows, I mean like remote desktopn in Windows, where you can control the pc remotely

  5. ben says:

    stan: you don’t need sshfs to do remove desktop type stuff with X over ssh.

    probably the easiest way is to start another X session on the local machine and use it to run X in over ssh. this would all be from the text login (F1):

    > X :1 &
    > export DISPLAY=:1
    > ssh -Y user@host
    user@host> gnome-session &

    then gnome should be running on display :1 (F9)

    the only problem i’ve seen is when you quit the gnome session on the remote server gnome will likely leave some things running and you won’t be able to exit the ssh session with killing them. stuff like x-screensaver etc. i assume this would be similar with kde too.

  6. audun (from Norway) says:

    I really don’t recommend this method, at least I had quite a few problems with it. I used sshfs to mount a server and had troubles with both file transfers and rights.

    Both Nautilus (“Connect to server” in Ubuntu Gnome) and Konqueror support ssh for remote connections, and it works much better.

  7. Brian says:

    @ Audun,

    The connect to server option in Gnome actually uses SFTP which is a subsystem of SSH. If SFTP is not enabled on the SSH server’s config file, you won’t be able to connect.

  8. neil_olner says:

    Finally got this to work after several attempts. In case others are having problems here’s some clarifications:

    1.replace root in the following with your username: sudo chown root:fuse /dev/fuse
    2. location of fusermount is /bin/fusermount (in kubuntu anyway), so use:
    sudo chmod +x /bin/fusermount
    or find it with whereis fusermount

    Also, since I was not using the user I installed with I had to add give the user privs to use sudo first – search on SudoRoot above

    Hope this helps!

  9. bob says:

    What you have to do is
    1. on the remote server, chmod 777 the directory you wish to connect to
    2. Create a mount point at local machine and chmod 777 it too
    3. mount with sshfs

  10. bob says:

    Also, if you want to get a hard drive icon (as if it were a local disk) on your desktop and on the places menu, create the local mount point in the /media folder.

  11. incd says:

    What you have to do is
    1. on the remote server, chmod 777 the directory you wish to connect to
    2. Create a mount point at local machine and chmod 777 it too
    3. mount with sshfs

    Do NOT chmod directories 777. It’s just plain stupidness. It really is not secure way.

  12. montanamax says:

    Awesome tutorial! I’m running kubuntu 8.10 and just completely skipped the sudo chmod +x /bin/fusermount step and everything worked great – thanks!

  13. manda says:

    in ubuntu 9.04 there’s no fuse module… so how can i do this tutorial in ubuntu 9.04

  14. Rex says:

    Thank you for this very useful article. for those whom it may concern, On Ubuntu Lucid Lynx, there is no need to install fuse, just apt-get install sshfs and issue the sshfs user@server/directory /path/to/local/directory command and it will work


  15. Vincent says:

    Hi all,

    Actually you doesn’t need sshfs to mount remote ssh folder, nautilus include this functionnality natively !

  16. JKT says:

    In a fresh install of Ubuntu 11.0.4, the very first step, apt-get, yields “E: Unable to locate package sshfs”. What is the method to fix this?

  17. milad a says:

    Hi, is there a way to enter the password without being prompted. Let’s say I wanna add “sshfs username@ipaddress:/remotepath ~/remoteserv” in fstab.. it wouldn’t work, would it?

  18. Jason says:

    @milad a: You could use SSH key authentication so that it doesn’t need a password, instructions to do so are here:

    They are written for Ubuntu, but should work for any most distributions.

  19. Tom says:

    Thanks for the tutorial. I was able to get it working.

    However I have a question. How do you unmount this drive once you’re done with it?

Leave a Reply

Your email address will not be published. Required fields are marked *