I use pam_mount to decrypt (gocryptfs) and mount my home directory:
# /etc/pam.d/system-login excerpt # ... session [success=2 default=ignore] pam_exec.so quiet /usr/bin/mountpoint -q "/home/$PAM_USER" session [success=1 default=ignore] pam_succeed_if.so service = systemd-user quiet session optional pam_mount.so # ... <!-- /etc/security/pam_mount.conf.xml excerpt --> <!-- ...defaults... --> <!-- Encrypted home --> <volume user="%(USER)" fstype="fuse" options="nodev,nosuid,quiet,nonempty,allow_other" path="/usr/bin/gocryptfs#/home/%(USER).cipher" mountpoint="/home/%(USER)" /> </pam_mount> This works well for a single tty. The problem is if I open another, though my pam_exec line prevents it trying to re-mount, when I exit that second tty, it still unmounts. (Worse, it doesn't even unmount correctly, leaving 'transport endpoint is not connected', and I have to manually fusermount -uz "$HOME". I tried adding <fuseumount>fusermount -uz %(MNTPT)</fuseumount> to the config, but no change.)
How can I prevent pam_mount from unmounting until the last session exits? (If tty1 that created the mount exited before tty2, I would want it to be kept mounted for tty2 even though it skipped mounting it itself.)
In fact, with <debug enable="1" /> it logs:
May 03 15:19:39 hostname login[6607]: (pam_mount.c:441): pmvarrun says login count is 1 May 03 15:19:39 hostname login[6607]: (pam_mount.c:734): username seems to have other remaining open sessions May 03 15:19:39 hostname login[6607]: (pam_mount.c:743): pam_mount execution complete but then the next thing is everything complaining that 'transport endpoint is not connected', and sure enough I have no home dir in the first tty.
I've also noticed if I then fusermount -uz $HOME, it actually ends up mounted, as if pam_mount for the first login session (in which I manually unmount it to fix the error, expecting to have to manually mount it again) is automatically re-mounting it?