Page 1 of 5 123 ... LastLast
Results 1 to 10 of 49

Thread: HOWTO: sshfs (mounting remote directories trough ssh)

  1. #1
    Join Date
    Jul 2006
    Location
    Montréal, Québec, Canada
    Beans
    58
    Distro
    Ubuntu 11.04 Natty Narwhal

    HOWTO: sshfs (mounting remote directories trough ssh)

    sshfs is a good way to easily mount folders from a remote host that you can access trough ssh. This tutorial assumes that you have openssh installed on the server. (Easy way: sudo apt-get install openssh-server)

    On the client you will have to install sshfs and its dependencies (fuse-utils and libfuse2)
    Code:
    sudo apt-get install sshfs
    Now load the fuse module :
    Code:
    sudo modprobe fuse
    Create the directory where the share is to be mounted :
    Code:
    mkdir /home/user/local/mountpoint
    *Of course change the path to fit your needs

    You are now ready to mount the share :
    Code:
    sudo sshfs username@IPorHOSTNAME:/remote/folder/to/mount /home/user/local/mountpoint
    Ex: sshfs bobbrown@bobserver.net:/home/bob /mnt/bobshome
    Now you can use the remote directory as if it was local!

    If you get an error saying :
    fusermount: failed to open /dev/fuse: permission denied
    adding your user to the fuse group should solve the issue.

    Code:
    sudo addgroup yourusername fuse
    Additional recommended step
    These steps are not required to make sshfs work but are recommended if you plan on using sshfs alot and will save you some time.

    Add the fuse module to /etc/modules
    Code:
    sudo gedit /etc/modules
    add fuse at the bottom of the list, this will load the fuse module each time you boot.

    Change permissions of fusermount
    Code:
    sudo chmod +x /usr/bin/fusermount
    Once this is done you wont need to use sudo to mount directories using sshfs.

    There is also the possibility to mount the share when you boot using /etc/fstab but I'm not sure how to do it yet.
    Registered Ubuntu user #8233

  2. #2
    Join Date
    Dec 2005
    Location
    Greensboro, NC
    Beans
    143
    Distro
    Ubuntu 9.10 Karmic Koala

    Re: HOWTO: sshfs (mounting remote directories trough ssh)

    Is there a way to have this do port forwarding as well?
    What I love about Linux: everything is just one command away. Just use && liberally.

    Check out for my "blog".

  3. #3
    Join Date
    Jan 2006
    Beans
    67
    Distro
    Kubuntu 6.10 Edgy

    Re: HOWTO: sshfs (mounting remote directories trough ssh)

    It took me a while to work it out but finally i found a way to automount sshfs on startup so ill share it here.

    first of all you need to create a public/private key pair for the server your logging into so you dont have to use a password.
    Code:
    ssh-keygen -t rsa
    Just keep hitting return you dont have to wory about any of the options.
    then cd to the ssh directory
    Code:
    cd ~/.ssh
    if there is authorized_keys file already in the .ssh directory back it up.
    Code:
    cp authorized_keys authorized_keys$
    then
    Code:
    cat *.pub >> authorized_keys
    Then copy the auhorized_keys to the ~/.ssh directory of the server and you can then ssh in without a password.
    once that is done you can create a simple script in your ~/.kde/Autostart directory to mount it all when you login. (not sure where the autostart directory is in gnome)

    Code:
    !/bin/bash
     # mount sshfs drive
    sshfs 192.168.1.101:/directory /mnt/to/whereever
    then make the script executable
    Code:
    chmod a+x nameofscript
    And your done.
    I hope this helps someone.

  4. #4
    Join Date
    Apr 2006
    Beans
    44

    Re: HOWTO: sshfs (mounting remote directories trough ssh)

    Hey man

    Great howto thx. Worked out of the box on both dapper and breezy for me. Did anyone compare speed and responsiveness with openvpn solutions???

    CYA
    Rune Kaagaard
    http://rune@runelyd.dk

  5. #5
    Join Date
    Jul 2005
    Location
    Seattle, WA
    Beans
    279
    Distro
    Kubuntu 5.10

    Re: HOWTO: sshfs (mounting remote directories trough ssh)

    Thanks for the howto.
    One question: I'm trying to get write access to my sshfs fuse mounted directories. but even using -o uid=[group id e.g.1000] which mounts it with my user id, i still can't write to the shares unless i am root.

    So I thought it might be a fuse permissions thing and added myself to the fuse group as you said, and then changed the permissions as you suggested. But I still can't mount shared without sudo first, without sudo i still get
    fuse: failed to exec fusermount: Permission denied
    - any thoughts on this? Were others able to mount all your shares without sudo and do they then get mounted with the correct permissions such that you can write to them? I checked that I am in the fuse group in the control panels (I am) and that the group on /dev/fuse and /usr/bin/fusermount is fuse and is executable.

    Thanks!
    jet

    EDIT: all that and it seems at least the problem with permissions simply required a reboot - probably to load the fuse modules with the new permissions.... But still I can't write to the directories - the permissions say they're all mine and writable but they aren't.

    EDIT: more info, i found it interesting the difference I get now that I'm adding it under my account, it seems it's not a permissions but that it's not allowing the "operation???"
    jet@ubuntu:~/rsync$ sudo mkdir asdf
    mkdir: cannot create directory `asdf': Permission denied
    jet@ubuntu:~/rsync$ mkdir asdf
    mkdir: cannot create directory `asdf': Operation not permitted
    Last edited by jetpeach; November 5th, 2006 at 10:39 AM.
    My Blog.

  6. #6
    Join Date
    Oct 2006
    Beans
    97

    Re: HOWTO: sshfs (mounting remote directories trough ssh)

    i'm having a strange issue...

    ner0tic@blackhawk:/mnt$ rm vendetta
    rm: cannot remove `vendetta': Is a directory
    ner0tic@blackhawk:/mnt$ rm -r vendetta
    rm: cannot lstat `vendetta': Permission denied
    ner0tic@blackhawk:/mnt$ sudo rm -r vendetta
    rm: cannot lstat `vendetta': No such file or directory
    ner0tic@blackhawk:/mnt$ mkdir vendetta
    mkdir: cannot create directory `vendetta': File exists
    this is my sshfs mount point. i followed the steps and it all looked good but i can't access it nor remove it. it acts as if it's not there when it is

  7. #7
    Join Date
    Jul 2005
    Location
    Seattle, WA
    Beans
    279
    Distro
    Kubuntu 5.10

    Re: HOWTO: sshfs (mounting remote directories trough ssh)

    i think the problem is even sudo doesn't have permission to remove your mountpoint until after it is unmounted (it is currently mounted when you tried to remove it?). try
    sudo umount /mnt/vendetta
    after that you should be able to remove it with sudo rm etc...
    My Blog.

  8. #8
    Join Date
    May 2006
    Location
    Finland
    Beans
    647

    Re: HOWTO: sshfs (mounting remote directories trough ssh)

    Quote Originally Posted by crazymonkey View Post
    Change permissions of fusermount
    Code:
    sudo chmod +x /usr/bin/fusermount
    Once this is done you wont need to use sudo to mount directories using sshfs.
    Now
    Code:
    ls -l /usr/bin/fusermount
    outputs
    -rwsr-xr-x 1 root fuse 18328 2006-05-11 20:45 /usr/bin/fusermount
    Then I try to mount using sshfs without sudo, and first it asks password, but after I return it, I get
    fusermount: user has no write access to mountpoint /media/kielo
    So it did not help. However, if I change permissions of my mountpoint like this
    Code:
    sudo chmod a+w /media/kielo
    , I can mount the directory by sshfs without using sudo.

  9. #9
    Join Date
    Jul 2005
    Location
    Seattle, WA
    Beans
    279
    Distro
    Kubuntu 5.10

    Re: HOWTO: sshfs (mounting remote directories trough ssh)

    jis, this behavior makes sense to me at least. the normal user can't write to /media/kielo so a normal user can't mount something there either unless the permissions of it are changed.

    your solutions of changing the permissions of /media/kielo is fine (though i wouldn't make it all writable, just change the ownership or something, all isn't good practice for security) or, as i do, just use a mount point in your users home directory, something like /home/yourUsername/kielo (make the directory first of course). then it's just like any other folder in your home directory and you'll be able to mount there.

    of course, i haven't been able to fix the write problems after mounting that i've described above still.
    My Blog.

  10. #10
    Join Date
    May 2006
    Location
    Finland
    Beans
    647

    Re: HOWTO: sshfs (mounting remote directories trough ssh)

    jetpeach, I had have the same permissions drwxr-xr-x for /media/floppy than for /media/kielo before and I can mount /media/floppy for writing but could not mount /media/kielo with sshfs. Mount program did change the ownership of /media/floppy from root to my current local user account. When I later changed permissions of /media/kielo as described before, and then mounted by sshfs, it changed ownership to some number and permissions to drwx--x--x .

    I don't know if there is any advantage of using a mount point in /home. How could an attacker use unmounted /media/kielo? (If the mount point is not empty, sshfs outputs
    fusermount: mountpoint is not empty
    fusermount: if you are sure this is safe, use the 'nonempty' mount option
    and does not mount there.) But anyway using mount point in /home is not less safe for sure, so thanks for the hint.

Page 1 of 5 123 ... LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •