linux - How to configure automounter with FUSE sshfs

12
2013-08
  • dietbuddha

    Is there a way to configure the automounter (either Linux or OSX) with FUSE sshfs so that cd /servers/<server> will automount the correct server with sshfs?

  • Answers
  • Manwe

    I just replied with an example answer to another question (autofs+sshfs-answer)

    Remember! Autofs user by default is root. So get sshfs working with root first.

    auto.master line

    note! use your own uid and gid and specify your prefered mount point I use /auto/mehtod/address

    /auto/sshfs /etc/auto.sshfs uid=1000,gid=1000,--timeout=60,--ghost
    

    auto.sshfs this is a bit more generic than just one mount

    #!/bin/bash
    
    # Shell script that acccepts one argument, namely userid@server
    # env >> /tmp/env_check
    # whoami >> /tmp/env_check
    
    key=$1
    USER='your_local_user_used_for_ssh_identity_file'
    REMOTEDEFAULT='default_to_this_user_otherwise_root'
    key=${key//[: #]/}
    
    # add user
    [[ ! "$key" =~ "@" ]] && key="${REMOTEDEFAULT}@${key}"
    
    case $key in
       ${REMOTEDEFAULT}@.Trash*)
          exit 1;;
       *)
          (
          echo "-fstype=fuse,idmap=user,rw,nodev,nonempty,transform_symlinks,noatime,allow_other,IdentityFile=/home/${USER}/.ssh/id_dsa,max_read=65536\\"
          echo -e "\t /uhome :sshfs\#$key\:\\"
          echo -e "\t /tmp :sshfs\#$key\:\/tmp\/\\"
          echo -e "\t /rootfs :sshfs\#$key\:\/")
    esac
    
    ## this is a bit more complex. It creates subfolders to autofs-mount/remotename
    ## /uhome  = your remote homedirectory
    ## /rootfs = remote root '/'
    ## /tmp    = remote tmp # same as /roots/tmp
    

    then link to folder you want to access ln -s /auto/sshfs/[email protected]/uhome/ remote-home


  • Related Question

    connection - sshfs mounted directory becomes unresponsive
  • gms8994

    I've mounted a directory via sshfs:

    sshfs <user>@<host>:/var/www <host>/
    

    However, after a few hours, the "something" happens, and I can no longer use the mounted directory. Symptoms are similar to when an nfsmounted server becomes unavailable: ls fails, cd fails, etc.

    I've attempted

    sshfs -o reconnect <user>@<host>:/var/www <host>/
    

    but that never responded.

    Does anyone know how I can either unmount the directory, and remount it, or force sshfs to reconnect to the server?


  • Related Answers
  • brice

    well, unmount-remount is easy enough

    fusermount -u ~/mountpoint
    sshfs user@host:/dir ~/mountpoint
    

    Done! As a sidenote, do you have ssh keepalive set to no on your server? You might simply be getting timed out.