Skip to content

Instantly share code, notes, and snippets.

@mzpqnxow
Last active December 10, 2021 20:57
Show Gist options
  • Save mzpqnxow/ce8fbfb6fe10e5e722425ecd1d80d506 to your computer and use it in GitHub Desktop.
Save mzpqnxow/ce8fbfb6fe10e5e722425ecd1d80d506 to your computer and use it in GitHub Desktop.
Build ecryptfs-utils from source on Debian 10
#!/bin/bash
set -e
#
# As of 11/24/2019, Debian still can't get it together with ecryptfs-utils so there
# is no longer an ecryptfs-utils in the apt repositories, removing the ability for
# a user to use ecryptfs at all, unless they build from source and manually configure
# the system
#
# Before using this, please see the status of the bugreport:
#
# https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=765854
#
# Basically, Debian removed the apt package until this bug can be fixed. The problem
# was that private ecryptfs mounts were not being unmounted on logout, almost completely
# voiding the value of the functionality :<
#
# If the bug is not yet fixed, you can use this script/guide to get ecryptfs per-user
# home directory encryption working
#
# This is probably a bit broader than necessary, but many of these are requirements to
# build ecryptfs-utils. Others, such as rsync and lsof are included as they are required
# for ecryptfs-migrate-home at runtime
DEPS="gpgv2 intltool keyutils libgpgme-dev libkeyutils-dev libnss3-dev libpam-dev \
libpam-pkcs11 libpkcs11-helper1-dev libtspi-dev python2-dev python3-dev \
simple-tpm-pk11 rsync lsof build-essential"
# You can use /opt/ecryptfs or something if you don't want it in your root
# Using something other than /usr may cause issues due to assumptions made in this script!
PREFIX=/usr
apt-get update
echo -n 'Press enter to install dependencies via apt-get ...'
apt-get install $DEPS
cd /usr/src
echo 'WARN: The source package is downloaded from the distribution site, but no signature check is performed!'
echo -n 'Press enter to download version 111 of ecryptfs-utils from the distribution site ...'
read x
# Change the link to a different version if desired, but other versions are untested
# This is the latest version as of 2019-11-24 ...
wget https://launchpad.net/ecryptfs/trunk/111/+download/ecryptfs-utils_111.orig.tar.gz
# You should check the signature here, probably
tar -xvzf ecryptfs-utils_111.orig.tar.gz
cd ecryptfs-utils-111
echo 'NOTE: if the following step fails, you may need to apt-get some additional dependencies'
echo -n 'Press enter to configure, build and install ecryptfs-utils from source ...'
read x
./configure LIBS='-lkeyutils -lnss3 -lnssutil3' --prefix=/usr KEYUTILS_LIBS='-lnss3 -lnssutil3' NSS_CFLAGS='-I/usr/include/nss -I/usr/include/nspr'
make -j && make install
cd
echo 'The ecryptfs-utils are now installed on your system, but there is more to do'
echo 'Step 1 - fix pam so that mounting is automated'
echo -n ' Add auth required pam_ecryptfs unwrap to pam common-auth? Enter to continue... '
read x
echo 'auth required pam_ecryptfs.so unwrap' >> /etc/pam.d/common-auth
echo -n ' Add auth optional pam_ecryptfs unwrap to /etc/pam.d/common-session? Enter to continue... '
read x
echo 'session optional pam_ecryptfs.so unwrap' >> /etc/pam.d/common-session
echo 'Done fixing PAM. If you want configuration/migration of users to use ecryptfs to work, it is necessary'
echo 'to add the setuid bit to /usr/sbin/mount.ecryptfs_private'
echo 'Step 2 - fix permissions on mount.ecryptfs_private so setreuid succeeds at runtime'
echo -n ' Use chmod to set setuid bit on mount.ecryptfs_private? Enter to continue ... '
read x
chmod u+s /usr/sbin/mount.ecryptfs_private
echo 'Done. Consider the following manual steps for increased security:'
echo ' 1. Create a group called "ecryptfs" using "groupadd ecryptfs"'
echo ' 2. Place "trusted" users who should be allowed to user ecryptfs in that group by editing /etc/group'
echo ' 3. Use "chmod 4750 && chgrp /usr/sbin/mount.ecryptfs_private ecryptfs" to protect the mount app'
echo
echo 'Installation and configuration complete!'
echo 'Try using ecryptfs-migrate-home to migrate a user to an encrypted home directory'
echo 'Make sure you test to ensure things are working, this is not official documentation!'
@b00mbox
Copy link

b00mbox commented Mar 28, 2020

Great. Thanks.

@seriousramius
Copy link

Thank you. After the restart i got the message: ERROR: Cannot get ecryptfs version, ecryptfs kernel module not loaded?
After running: modprobe ecryptfs the module is loaded and the migration run's well. Regards

@leephillips
Copy link

I really appreciate this! It saved me a load of time (and works out of the box).

@mzpqnxow
Copy link
Author

@leephillips happy it was helpful for you- btw, you should take a look at https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=765854, it seems to suggest Debian may be including the package again soon

@c13-github
Copy link

c13-github commented Dec 10, 2021

@mzpqnxow (thanks for the gist), @leephillips. I realize Debian should own this; as of Buster encfs ecryptfs still looks deprecated. I get as far as 46:

45 ./configure LIBS='-lkeyutils -lnss3 -lnssutil3' --prefix=/usr KEYUTILS_LIBS='-lnss3 -lnssutil3' NSS_CFLAGS='-I/usr/include/nss -I/usr/include/nspr' #ran as sudo
46 make -j && make install #ran as sudo
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
<..>output available on request

42 echo 'NOTE: if the following step fails, you may need to apt-get some additional dependencies'
suggests that the swig warning should be heeded. latex, ps2pdf, latex2html, dvips are less clear. Were they required for successful build?

The build errors I see suggest deprecation of operations, (initialization, state checks and key generation). The permissions failure is unclear:

ecryptfs_key_mod_openssl.c:155:25: error: dereferencing pointer to incomplete type ‘RSA’ {aka ‘struct rsa_st’} nbits = BN_num_bits(key->n); ecryptfs_key_mod_openssl.c:281:2: warning: implicit declaration of function ‘CRYPTO_malloc_init’; did you mean ‘CRYPTO_malloc’? [-Wimplicit-function-declaration]
CRYPTO_malloc_init();
ecryptfs_key_mod_openssl.c:318:2: warning: ‘ERR_remove_state’ is deprecated [-Wdeprecated-declarations] ERR_remove_state(0); ecryptfs_key_mod_openssl.c:355:2: warning: ‘RSA_generate_key’ is deprecated [-Wdeprecated-declarations]
`ecryptfs_key_mod_openssl.c:1029:1: fatal error: opening dependency file .deps/libecryptfs_key_mod_openssl_la-ecryptfs_key_mod_openssl.Tpo: Permission denied

@leephillips
Copy link

I don’t use encfs. I use libecryptfs and mount the loopback FS manually. And this works again, on Debian 11.

@c13-github
Copy link

Corrected the package name to make it more clear I'm referring to the one in the gist. @leephillips will certainly try this on Debian 11 as written.

@leephillips
Copy link

I don’t compile it, I just install the package from the repository. And it works now on Debian 11.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment