How do I make sure that all users have their home directory encrypted when the login for the first time?
I have setup pam to use Kerberos authentication and LDAP authorization (which I think should not really have any effect on ecryptfs).
I have also setup pam-mkhomedir to create the home directories from /etc/skel in which I have placed some standard configurations.
Looking at the .ecryptfs directory in one user account that already has ecryptfs enabled, there are some user-specific configurations, such as the mountpoint (set to /home/d_inevitable) for example, which would be no good in /etc/skel.
Also the configurations in /etc/skel would need to be copied after the home directory has been mounted with ecryptfs.
I have managed to get it to work using pam_exec:
Create a script to setup ecryptfs for all new users in
/etc/security/ecryptfs
:Make sure the script is executable:
Add entry to execute it with pam_exec on auth:
Add the following lines:
The
pam_exec
is set to required, because it will not setup ecryptfs if the script doesn't run as root. This is the case ifsu
is used from a non-root user. So if ecryptfs is not setup andsu
is used (that is when the user attempts to login for the first time usingsu
) then his will get refused. As such we ensure that the user cannot login without an ecryptfs setup.Create another script to populate the home directory in place of pam_mkhomedir
This script will copy everything in /etc/skel if the file .donotremove doesn't exist.
Also make sure this file is executable:
Add another entry to execute this script on a session
Add the following lines:
Now LDAP users can login and have an ecryptfs encrypted home directory.
Update
Instead of editing the files in
/etc/pam.d
directly (which is generally not recommended), it is better to apply the settings as a PAMConfig profile.Just paste this code into a new file
/usr/share/pam-configs/ecryptfs-nonlocal
:And then run
pam-auth-update
:Check
Enable EcryptFS for users from remote directories such as LDAP.
and make sure thateCryptfs Key/Mount Management
is unchecked. Leave all other options up to your preferences.This will make sure that relevant configs in
/etc/pam.d
are applied and that they stay there.