Page 2 of 14 FirstFirst 123412 ... LastLast
Results 11 to 20 of 139

Thread: SSHFS AUTOmount on Feisty

  1. #11
    Join Date
    Jun 2007
    Beans
    2

    Question Re: SSHFS AUTOmount on Feisty

    Hi,

    I am trying to do this for all my users that are able to connect from different workstations to the server.

    First I assumed that I should use the root user as a user name, but than it only works for the root user and not for any other user.

    How can I have this done for all users without adding one for each user to fstab?

    Cheeers
    ... LuckyProphet

  2. #12
    Join Date
    Mar 2006
    Beans
    14

    Talking AUTOmount at Boot Time (on Feisty)

    • Allow each PC's root to do the passwordless logon to the myServer PC

    • Create - adjust - install this batch file. I used Webmin Boot commands panel to create and install the base batch file - sorry, I am not versatile in boot sequences, etc. Webmin picked the spot. Then I modified it to create the inside.

    Code:
    #!/bin/sh
    # Mount shares controlled by FUSE
    case "$1" in
    'start')
        `fusermount -u -z /myGlobal`
        `sshfs admin1@myServer:/myGlobal /myGlobal -o allow_other -o nonempty`
        if [ ! -e /myGlobal/automountFUSE_OK ]
        then
          `sshfs admin1@my.remote.net:/myGlobal /myGlobal -p 1022 -o allow_other -o nonempty`
        fi
        ;;
    'stop')
        `fusermount -u -z /myGlobal`
        ;;
    *)
        echo "Usage: $0 { start | stop }"
        ;;
    esac
    exit 0
    • Don't forget to create the file /myGlobal/automountFUSE_OK on myServer


    In my case ...
    • Every PC has a (sudo root) admin1 account

    • Every PC has a /myGlobal mountpoint (directory) used to auto-mount the /myGlobal directory residing on myServer

    • The back-tick is required on the web connection's sshfs command - I back-ticked all of them just because.

    • My router deflects the incoming port (-p 1022) to myServer's ssh port 22 (I have ports 1122, 1222, etc. pointing to other PCs). Hopefully, if myServer isn't on the LAN, I'll find it on the web.

    • No timeout is used - why would I? sshfs will timeout by itself. Likewise, no error logs, etc. Again, why?

    • No - you do not need shares defined - no Samba, no NTFS
    Last edited by lindsay_keir; June 20th, 2007 at 05:07 AM. Reason: Left out no shares, Samba, NTFS, etc.

  3. #13
    Join Date
    Apr 2005
    Beans
    849

    Re: SSHFS AUTOmount on Feisty

    I'm having some problems using the automount feature.
    that is, problems with
    Code:
    /etc/network/if-up.d/mountsshfs
    I've got a user on the system and this user has copyed the ssh-key stuff to the server,
    so this user is able to run sshfs by commandline, without entering password.

    And if this user manually runs
    Code:
    /etc/network/if-up.d/mountsshfs
    It will work.

    But if the user running the script is root(as it is when run by the system),
    the sshfs will not work and the system ask for the password.

    Any ideas?

    thanks in advance

  4. #14
    Join Date
    Feb 2007
    Beans
    77

    Re: SSHFS AUTOmount on Feisty

    Actually, I have the same problem. The only reason it worked initially is because I foolishly had the same ssh keys in my home and in the root directory. However, I have modified my script to work whether called by a user or by root. Furthermore, when invoked by a user, it will only attempt to mount that user's own mount points. I'll edit my first post accordingly.

  5. #15
    Join Date
    Jun 2007
    Location
    USA
    Beans
    524
    Distro
    Kubuntu 10.04 Lucid Lynx

    Re: SSHFS AUTOmount on Feisty

    I keep getting this error whenever I try to automount:

    [mntent]: line 19 in /etc/fstab is bad
    mount: can't find /home/username/Desktop/sshfs projects in /etc/fstab or /etc/mtab

    I can and regularly do sshfs to this exact folder which I created for that purpose, so whats the deal? I followed your guide quite closely so im wondering what I could have done wrong. Heres my fstab entry:

    # fuse mounts
    sshfs# username@fileserver:/path/to/file/ /home/username/Desktop/sshfs\ projects/ fuse comment=sshfs,users,noauto,uid=1000,gid=1000,allow _other,reconnect,transform_symlinks 0 0

    Names and IP's are changed as needed here obviously. Anyway, what gives?

    Edit: Ok so im a moron

    I had a space after the sshfs# and some spaces in the paths. Anyway, fixed that in fstab and all is well

    Great guid btw and thanks a ton!
    Last edited by buntunub; July 24th, 2007 at 02:55 AM.

  6. #16
    Join Date
    Feb 2007
    Beans
    77

    Re: SSHFS AUTOmount on Feisty

    I have to make several updates and fixes to my guide, but for those who are waiting, here is the updated script that should work whether it is run as root or as a normal user, with the important caveat that in order to run as root, you must give each fstab entry an owner with the option uid=yourusername. For fstab entries without this option, this script will function identically to the previous one.

    Also, this is exactly the script I am using. I have not yet attempted to make the comments intelligible to anyone but myself. That's one thing I intend to do before adding this script to my guide.

    Code:
    #!/bin/sh
    
    isa_number () {
        ! echo $1 | egrep -q '[^0-9]'
        return $?
    }
    
    user_from_uid () {
        # we need a number
        if ! isa_number $1
        then
            return 1
        fi
        
        local IFS=":"
        while read name x uid the_rest
        do
            if [ "$1" -eq "$uid" ]
            then 
                echo "$name"
                return 0
            fi
        done </etc/passwd
        return 1
    }
    
    
    # Not for loopback
    [ "$IFACE" != "lo" ] || exit 0
    
    # comment this for testing
    exec &>/dev/null # squelch output for non-interactive
    
    # unmount them first
    mounted=`grep 'sshfs#' /etc/mtab | awk '{ print $2 }'`
    [ -n "$mounted" ] && umount -l $mounted
    
    while read fs mp type opts dump pass extra
    do
        # check validity of line
        if [ "`expr substr ${fs}x 1 1`" = "#" -o -z "$pass" -o -n "$extra" ]; then
            # line is a invalid or a comment
            continue
        # check if the line is an sshfs line
        elif echo $opts | grep -q 'comment=sshfs'; then
            #find out the user 
            mp_uid=`echo $opts | egrep -o 'uid=\w+'` # "mp" stands for mount point
            if [ -z "$mp_uid" ]; then
                # no uid was specified, so just try to mount as the current user
                mount $mp
            else
                mp_uid_length=`expr length $mp_uid - 3`
                mp_uid=`expr substr $mp_uid 5 $mp_uid_length` # delete the "uid="
                # mp_uid now contains either a username or a uid
                # convert to username if possible; otherwise assume that it already is one
                if ! mp_user=`user_from_uid $mp_uid`; then
                    mp_user=$mp_uid
                fi             
                # mp_user is either a username or an invalid uid; either way is ok
                if [ "$mp_user" = "`whoami`" ]; then
                    # current user owns the mount, so mount normally
                    mount $mp
                elif [ "`whoami`" = "root" ]; then
                    # running as root, so su to user and mount
                    su $mp_user -c "mount $mp"
                fi
                # otherwise, don't try to mount another user's mount point
            fi
        fi
        # if not an sshfs line, do nothing
    done </etc/fstab
    Last edited by Darwin Award Winner; July 24th, 2007 at 03:37 AM.

  7. #17
    Join Date
    Apr 2005
    Beans
    849

    Re: SSHFS AUTOmount on Feisty

    Thanks your updated script fixed my problem

  8. #18
    Join Date
    Aug 2007
    Beans
    19

    Re: SSHFS AUTOmount on Feisty

    I'd like to point out that RSA keys mean SSH protocol 1, which is less secure than DSA keys//SSH protocol 2. Just use these steps to get SSH to use protocol 2:
    Actually my original post is wrong. SSH protocol can use RSA or DSA keys. There is apparently not much difference between the keys.

    Thanks for howto on sshfs. It helped me out immensely.
    Last edited by yzf600; August 13th, 2007 at 05:40 PM.

  9. #19
    Join Date
    May 2007
    Beans
    Hidden!

    Re: SSHFS AUTOmount on Feisty

    Thanks. This is great. You read my mind with this tute. However, there is one niggle. Everything works great except that it doesn't mount on a reboot. It mounts if I run /etc/init.d/networking restart. It mounts if I run /etc/network/if-up.d/mountsshfs as a user. But it does not mount on reboot. What could be the problem here?

    PS thanks to #6 for the neat command ssh-copy-id

    I added this script to /etc/rc.local and it now mounts on boot.
    Last edited by mkramer; September 12th, 2007 at 06:29 PM. Reason: quick fix

  10. #20
    Join Date
    Feb 2007
    Beans
    77

    Re: SSHFS AUTOmount on Feisty

    Good news. I have updated the first post with a significantly updated scripts. Check the update for the new features.

    LuckyProphet, sshfs is not really designed for that sort of thing. This setup is more amenable to a single user who wants to connect to many ssh servers. You want the opposite: many clients connecting to one server. Your problem is better solved with traditional network filesystems, like NFS or samba.

Page 2 of 14 FirstFirst 123412 ... 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
  •