Mount remote filesystem via ssh protocol using sshfs and fuse [Fedora/RedHat/Debian/Ubuntu way]

sshfs

Imagine the following situation: you have to compile some Linux/Unix application or kernel module that requires kernel source present at your hard drive, say, in /usr/src/kernels/kernel-2.6.21-i386/ or elsewhere. But there is not enough disk space to copy these sources or install kernel-devel or linux-source packages (in Fedora/RedHat or Ubuntu/Debian distros respectively)… Sounds familiar? Believe me, sometimes it happens :)

As a solution you can mount the directory of some remote PC that contains needed kernel source. It can be done via several protocols like smb, ftp etc. In this article we will mount remote directory using ssh protocol that is one the most popular for remote and secure access to Linux boxes over the network.

Below are the steps which should be taken to get the ball rolling. We need two packages: sshfs and fuse-utils.

ssh1. Install necessary packages:

a. Ubuntu/Debian:

sudo aptitude install fuse-utils sshfs

b. Fedora/Centos/RedHat:

yum install fuse-sshfs fuse fuse-libs

c. Other Linux: download and compile sshfs/fuse from sources

2. Check that kernel module fuse is loaded:

lsmod | grep fuse

There should be the line containing “fuse” in the output (of not try modprobe fuse).

3. Mount remote filesystem using something like this (two commands):

mkdir -p /mnt/sshfs/
sshfs remote-user@remote-machine:/some/directory /mnt/sshfs

where remote-user is the username allowed to login remote-machine via ssh protocol. It will ask you to type the password so just type it and press return :)

4. That’s it. Good luck!

 
 
» You might also be interested in the following articles:
Set up mount count after system will be checked by e2fsck
Secure Linux/Unix system that runs OpenSSH
How to create custom linux ISO image?
Move linux to another hard drive (dump, restore, backup)
Local and remote X sessions on different consoles



» Want to stay up to date? Subscribe to our E-MAIL or RSS feed!

12 Responses to “Mount remote filesystem via ssh protocol using sshfs and fuse [Fedora/RedHat/Debian/Ubuntu way]”


  1. 1 YanK (web developer)

    Hello,

    I used this technique last week but it doesn’t work very well in ubuntu.
    If you use two differents users on ubuntu and the server and if you use gedit to edit a file in the sshfs it donsn’t work. Is not possible to update two time the same file in sshfs.
    I use the server connection in Nautilus to edit files on my servers.

    Sorry for my english, i am french. ;)

  2. 2 FoxyBingo

    This is so cool!

  3. 3 artiomix

    Hi, YanK! Which version of Ubuntu do you try? Those GUI tools you tried for mounting directories via ssh use sftp program instead of fuse/sshfs… When you use the way I described in the post you can handle mounted directory as local one — the only difference is the transfer speed :)

  4. 4 YanK (web developer)

    No no, I used exactly the same method as you.
    I am on ubuntu 8.10. I used sshfs and it work but is not possible to edit twice the same file with gedit. It work perfectly with KWrite.
    I saw others persons who had the same problem on French forums.

    Finnaly i use sftp with Nautilus and it work perfectly.
    I don’t know why fuse/sshfs don’t work with gedit.

  5. 5 SoaringEagleCasinoMTPleasant

    I haves use then and works

  6. 6 StreetCraps

    That is so nice!

  7. 7 BoulderStationLV

    I will try it!

  8. 8 jkh

    great instructions, thnx a lot!!
    i really needed this stuff to get synkron working with my netbook…

  9. 9 Johnhere

    Gr8 tutorial !

    But i cant find how to unmount it ;-)

    thnks

  10. 10 Joao Rodrigues

    To unmount, you should use:
    fusermount -u /mnt/sshfs
    where /mnt/sshfs is your mountpoint. This is the same for any FUSE filesystem, I guess.

    About the gedit problem:
    1) If gedit reports a permission problem, try passing “-o id=xxx” option to sshfs. (This worked for me with:
    SSHFS version 1.9
    FUSE library version: 2.7.2
    fusermount version: 2.7.2
    using FUSE kernel interface version 7.8)

    2) If gedit reports the file “has been modified since reading it” or something like that, then it reminds me of a similar situation over a SMB/CIFS mount. I’ve read bug reports on gedit for this (see https://bugs.launchpad.net/gedit/+bug/34813), but the developers seemed to disagree that it’s a bug. It seems to be related to the algorithm used to make backups: renaming files while open or something of the kind. Anyway one workaround was to downgrade gedit to version 2.12.x. (This worked over SMB/CIFS. It might be a different problem with sshfs.)

  11. 11 Adela Ziegelbauer

    Excellent post. I agree with your viewpoint on this. Thanks again for the quality content, more webmasters should follow the way you do things!

  1. 1 » Mount remote filesystem via ssh protocol using sshfs and fuse News from the void…

Leave a Reply




Friendly Sites:Who is behind Linux Screw?
GeekyBits³ | Bash Cures Cancer | OMG! Ubuntu!
My SysAd Blog | Web Upd8
ZEPY | Linux config Wiki | Planet Sysadmin
a non-geek's linux notes | Linux Today
Linux HOWTOs, Tutorials & Projects with Adam Palmer | LinuxAlt.Com
My name is Artem N. (artiomix AT gmail DOT com) and I'm Linux/Unix, Cisco systems engineer. The main idea of Linux Screw is to share relevant knowledge, skills and observations over The Web. Here you can find a lot of information related to different Linux distributions, FreeBSD, IOS as well as a other Open Source around staff. Read more ››