How To Encrypt Files in Linux with eCryptfs

Ads by Google

how to encrypt files in linuxMark 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:

Ads by Google

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 tutorial

Press ‘1’ to select passphrase

2) Selecting your encryption cipher

ecryptfs-cipher

Press Enter to select the default option [AES]

3) Select key bytes

ecryptfs-keybyte

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?

Join live MakeUseOf Groups on Grouvi App Join live Groups on Grouvi
Best Linux Apps
Best Linux Apps
19 Members
Linux for New Switchers
Linux for New Switchers
24 Members
Linux Distros Talk
Linux Distros Talk
11 Members
Master the Linux Command Line
Master the Linux Command Line
15 Members
Ads by Google
Comments (7)
  • 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.

  • 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.

  • 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.

    • 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.

  • Eli

    can ecrypt mount and decrypt volumes made with truecrypt?

Affiliate Disclamer

This review may contain affiliate links, which pays us a small compensation if you do decide to make a purchase based on our recommendation. Our judgement is in no way biased, and our recommendations are always based on the merits of the items.

For more details, please read our disclosure.
Affiliate Disclamer

This review may contain affiliate links, which pays us a small compensation if you do decide to make a purchase based on our recommendation. Our judgement is in no way biased, and our recommendations are always based on the merits of the items.

For more details, please read our disclosure.