How To Encrypt Files in Linux with eCryptfs

binary   How To Encrypt Files in Linux with eCryptfsMark has previously described how you can use TrueCrypt to encrypt your sensitive data. While that is a great encryption software, it requires you to pre-allocate a fixed size to the container before you can store confidential data to it. If you are using only 10% of the allocated space, the remaining 90% of the space goes to waste. If you are looking for a more dynamic solution to encrypt files in Linux, eCryptfs might be the solution for you.

eCryptfs is a stacked cryptographic filesystem embedded within the Linux kernel (versions 2.6.19 and later). Being a stacked filesystem, it can easily encrypt and decrypt the files on your Linux PC as they are written to or read from the hard disk.

The greatest advantage of eCryptfs is that all encryption is made at the single-file level. This means that you don’t have to create a fixed size container to hold your files.

There are several benefits of single-file level encryption:

  • Since each file is treated differently, on a shared platform/server/directory, you can have different files encrypted by different users and each user can access only his/her files.
  • All the cryptographic metadata is stored in the header of the file. This means that the encrypted file can be copied/moved from one location to another without losing its confidentality.
  • It requires no special on-disk storage allocation effort. You don’t have to pre-allocate 1GB (or more) of your hard disk space to store your sensitive data that maybe only few megabytes.

Installing eCryptfs

The installation method might differ in different distros. In Ubuntu 8.04 and above, you can install eCryptfs using the following command:

sudo aptitude install ecryptfs-utils

For Ubuntu 8.10

As eCryptfs is implemented in Ubuntu 8.10, you can easily set it up using the following command:

ecryptfs-setup-private

Once you have set it up Ubuntu 8.10, you will find a Private folder in your Home directory. To access to the folder, you need to mount it with this command:

mount.ecryptfs_private

You can now add your sensitive files into the Private folder. Encryption will be done as the file is added to the folder.

To unmount the folder, use the command:

umount.ecryptfs_private

For Ubuntu 8.04 or other Ubuntu-based distro

First create a folder in your Home directory and name it secret

mkdir ~/secret

Change the file permission so only you can access

chmod 700 ~/secret

Mount the eCryptfs to the secret folder

sudo mount -t ecryptfs ~/secret ~/secret

It will prompts you to answer a few questions:

1) Selecting your key type for newly created files

ecryptfs keytype   How To Encrypt Files in Linux with eCryptfs

Press ’1′ to select passphrase

2) Selecting your encryption cipher

ecryptfs cipher   How To Encrypt Files in Linux with eCryptfs

Press Enter to select the default option [AES]

3) Select key bytes

ecryptfs keybyte   How To Encrypt Files in Linux with eCryptfs

Press Enter to select the default option [16]

4) Enable plaintext passthrough

Type ‘N’ to select No.

That’s it. You can now add files into the secret folder.

To test the reliability of eCryptfs, unmount the secret folder and see if you can open the files inside the folder.

sudo umount ~/secret

If all is good, you should not be able to open any files inside the folder.

What other encryption methods you use to protect your files?

The comments were closed because the article is more than 180 days old.

If you have any questions related to what's mentioned in the article or need help with any computer issue, ask it on MakeUseOf Answers—We and our community will be more than happy to help.

7 Comments -

0 votes

Eli

can ecrypt mount and decrypt volumes made with truecrypt?

0 votes

Damien Oh

Why would you want to encrypt volume made with truecrypt?

0 votes

Sean

TrueCrypt does everything I want, and I can’t imagine why anybody would need to use something else. Especially with they dynamic size truecrypt volumes available, and an easy to use Linux version.

0 votes

bugmenot

What the hell are you talking about? It’s a completly different implementation (and way cooler). “Why do we need different ANYTHING?” — nice way of thinking, really.

0 votes

Max

While having an encrypted container is great, you still have some issues on a Linux system for potential files to write to swap and tmp. So if you’re going to go to the effort to create encrypted systems, you might want to consider going ahead and spending the extra time to do /tmp, /swap, and your /home partition.

Encryption does little good, if you have a file writing in and out of swap or tmp, that hasn’t been encrypted. And while whole disk encryption is good, from what I read, you really need only worry about /tmp, /swap, and /home to protect your data and personal files.

0 votes

Damien Oh

You are right on that. The main data lies on the /home folder, but in the process of writing and reading, it might be stored in the /swap and /tmp folders as well. Anyone who are interested can find more information at http://ecryptfs.sourceforge.net/ecryptfs-faq.html#deployment

0 votes

Encryption Software

I share a computer with my three roommates and even though we trust each, it gives us all peace of mind that each of our file sets are protected through eCryptfs. We do not tell each other our passwords, because that would defeat the purpose of using eCryptfs, but if someone needs access to one of my files, like an episode of The Office, they can ask me to grant them momentary access and I can sign them in. It’s pretty useful that way.