bashsambacifs

Unmount share on disconnect from SSH


I was able to get a windows share to mount when users ssh into our server in a sub-dir in ~. I now want it so that when they disconnect, the mount unmounts. I added this to /etc/bash.bashrc but it doesn't seem to work.

finish() {
    sudo /usr/local/bin/disconnect_mount.sh
}

trap finish EXIT

In the shell script I have this:

if ["$PAM_TYPE" = "close_session" ]; then
        sudo umount ~/D
fi

Solution

  • Created this script:

        #!/bin/sh
    
    sudo umount ~/D
    

    Then in /etc/bash.bashrc:

    #Disconnect mount on session close
    finish() {
     sudo /etc/bash.bash_logout
    }
    trap finish SIGHUP
    

    And in /etc/sudoers:

    ALL     ALL=(root) NOPASSWD: /usr/local/bin/disconnect_mount.sh