How to Encrypt Files with gocryptfs on Linux – How-To Geek

Fatmawati Achmad Zaenuri/Shutterstock

Do you want to encrypt important files, but not your Linux systems entire hard drive? If so, we recommend gocryptfs. Youll get a directory that, essentially, encrypts and decrypts everything you store.

Privacy is big news. Hardly a week goes by without the announcement of a breach at one organization or another. Companies either report recent incidents or disclose breaches that happened some time ago. In both cases, its bad news for those whose data has been exposed.

Because millions of people use services like Dropbox, Google Drive, and Microsoft OneDrive, a seemingly never-ending stream of data is pushed to the cloud every day. If you store some (or all) of your data on the cloud, what can you do to protect classified information and private documents should a breach occur?

Data breaches come in all shapes and sizes, of course, and theyre not limited to the cloud. A lost memory stick or stolen laptop is just a data breach on a smaller scale. But the scale isnt the critical factor. If the data is sensitive or confidential, someone else having it could be disastrous.

One solution is to encrypt your documents. Traditionally, this is done by encrypting your hard drive in its entirety. This is secure, but it also slightly slows down your computer. Plus, if you suffer a catastrophic failure, it can complicate the process of restoring your system from backups.

The gocryptfs system allows you to encrypt only the directories that need protection and avoid the system-wide overhead of encryption and decryption. Its fast, lightweight, and easy to use. Its also easy to move encrypted directories to other computers. As long as you have the password to access that data, it leaves no trace of your files on the other computer.

The gocryptfs system is constructed as alightweight, encrypted file system. Its also mountable by regular, non-root accounts because it uses theFilesystem in Userspace (FUSE) package. This acts as a bridge between gocryptfs and the kernel file-system routines it needs to access.

To install gocryptfs on ubuntu, type this command:

To install it on Fedora type:

On Manjaro, the command is:

Part of the glory of gocryptfs is how simple it is to use. The principles are:

Were going to create a directory called vault to hold the encrypted data. To do so, we type the following:

We need to initialize our new directory. This step creates the gocryptfs file system within the directory:

Type a password when youre prompted; youll type it twice to ensure its correct. Choose a strong one: three unrelated words that include punctuation, digits, or symbols is a good template.

Your master key is generated and displayed. Copy and save this somewhere safe and private. In our example, were creating a gocryptfsdirectory on a research machine thats wiped after each article is written.

As its necessary for an example, you can see the master key for this directory. Youll definitely want to be much more secretive with yours. If someone obtains your master key, they can access al of your encrypted data.

If you change into the new directory, youll see two files have been created. Type the following:

The gocryptfs.diriv is a short binary file, while gocryptfs.conf contains settings and information you should keep safe.

If you upload your encrypted data to the cloud or back it up to small, transportable media, dont include this file. If, however, you back up to local media that remains under your control, you can include this file.

With sufficient time and effort, it might be possible to extract your password from the encrypted key and salt entries, as shown below:

The encrypted directory is mounted on a mount point, which is simply an empty directory. Were going to create one called geek:

We can now mount the encrypted directory on the mount point.Strictly speaking, whats actually mounted is the gocryptfs file system inside the encrypted directory.Were prompted for the password:

When the encrypted directory is mounted, we can use the mount point directory the same as we would any other. Anything we edit and create in this directory is actually written to the mounted, encrypted directory.

We can create a simple text file, like the following:

We can edit it, add some content to it, and then save the file:

Our new file has been created:

If we switch into our encrypted directory, as shown below, we see a new file has been created with an encrypted name. You cant even tell which file type it is from the name:

If we try to view the contents of the encrypted file, we can see its truly scrambled:

Our simple text file, shown below, is now anything but simple to decipher.

When youre finished with your encrypted directory, you canunmount itwith the fusermount command. Part of the FUSE package, the following command unmounts the gocryptfs file system inside the encrypted directory from the mount point:

If you type the following to check your mount point directory, youll see its still empty:

Everything you did is safely stored in the encrypted directory.

Simple systems have the advantage of being used more often, while more complicated processes tend to fall by the wayside. Using gocryptfsisnot only simple, its also secure. Simplicity without security wouldnt be worthwhile.

You can create as many encrypted directories as you need or just one to hold all of your sensitive data. You might also want to create a few aliases to mount and unmount your encrypted file system and simplify the process even more.

RELATED: How to Create Aliases and Shell Functions on Linux

Excerpt from:
How to Encrypt Files with gocryptfs on Linux - How-To Geek

Related Post

Comments are closed.