Score:0

How to create ZFS home dirs using pam_exec

pt flag

How do I get pam_exec.so to create a new home dir ZFS dataset for each user who logs in via GDM/LDAP? I'm running Ubuntu 20.04, using GDM and nslcd for LDAP auth.

pam's mkhomedir library doesn't have native support for ZFS yet so I've filed a feature request for this on github. Until that gets implemented, I'll have to hack this together myself.

UPDATE: This is working when logging in to LDAP from the terminal, it just doesn't currently work with gdm (or lightdm).

UPDATE2: Got it working! Updated this post appropriately.

I added the following line to the end of /etc/pam.d/common-session

session     optional        pam_exec.so /usr/local/bin/mkzfshome.sh

/usr/local/bin/mkzfshome.sh

#!/bin/bash
if [ "$PAM_USER" != "gdm" ] && [ ! -d "/home/$PAM_USER" ] ; then
    zfs create -o mountpoint=/home/$PAM_USER astarray/home/$PAM_USER 
    chown $PAM_USER:1001 /home/$PAM_USER
    chmod go-rwx /home/$PAM_USER
fi

We ended up using lightdm instead of gdm so replace gdm with lightdm if you are using lightdm too.

Running mkzfshome.sh requires sudo/root permissions so we will configure sudo to give all members of the isdads-user group permission to run this script as root and without entering a password by running visudo and adding a line such as:

%isdads-user ALL=(ALL) NOPASSWD: /usr/local/bin/mkzfshome.sh

To the sudoers file, where isdads-user is a group that all of your users that will need to run mkzfshome.sh on login are a member of.

pt flag
Someone in #openzfs has pointed out `zfs allow` for mount doesn't work under Linux and so zfs allow can't be used for create either.
pt flag
I've updated the question to reflect that I now have this working from the terminal now but not from gdm or lightdm.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.