LLI Wiki — My Digital Knowledge Base

Encrypt a directory with eCryptfs on Linux

Interactive and non-interactive eCryptfs mounts on a directory, unmounting, and a pointer to LUKS.

eCryptfs is a stacked cryptographic filesystem for Linux. It can encrypt a directory in place by mounting it on top of itself. This note shows an interactive mount, a non-interactive mount with explicit options, and how to unmount. See also How to encrypt directories with eCryptfs in Linux.

Interactive mount

The source and the mount point are the same directory:

sudo mount -t ecryptfs ~/encrypt/ ~/encrypt/

The command prompts for the following choices:

Prompt Value used
Passphrase your own passphrase
Cipher aes (others offered: blowfish, des3_ede, twofish, cast6, cast5)
Key bytes 16 (32 and 24 also offered)
Enable plaintext passthrough n
Enable filename encryption y
Filename Encryption Key (FNEK) signature accept the proposed value

On success the command prints the options it uses, then Mounted eCryptfs:

Attempting to mount with the following options:
  ecryptfs_unlink_sigs
  ecryptfs_fnek_sig=<FNEK_SIGNATURE>
  ecryptfs_key_bytes=16
  ecryptfs_cipher=aes
  ecryptfs_sig=<FNEK_SIGNATURE>
Mounted eCryptfs

Non-interactive mount

Reuse the options printed by the interactive mount so that no question is asked:

sudo mount -t ecryptfs -o "rw,ecryptfs_cipher=aes,ecryptfs_key_bytes=16,ecryptfs_passthrough=n,ecryptfs_enable_filename_crypto=y,ecryptfs_fnek_sig=<FNEK_SIGNATURE>,verbose=0,no_sig_cache" ~/encrypt/ ~/encrypt/

The passphrase can also be passed in the options with key=passphrase:<PASSWORD>, but it then ends up in the shell history: prefer the interactive prompt.

Unmount

sudo umount ~/encrypt/

After unmounting, eCryptfs may print Could not unlink the key(s) from your keyring. Please use keyctl unlink if you wish to remove the key(s). Proceeding with umount. The unmount still proceeds.

Disk encryption with LUKS

To encrypt a whole partition or the root filesystem, use LUKS instead. See How to encrypt the root filesystem on Linux.

Mastodon LLIMastodon SocialFosstodon