Skip to main content

File encryption and decryption with ccrypt

Encrypting and decrypting files with the ccrypt package is easy to do and provides excellent security.
Red door with silver handle

Image by Mabel Amber from Pixabay

The ccrypt utility is a security tool that encrypts and decrypts files and streams on demand. It uses the Advanced Encryption Standard (AES), which is considered very secure. For the moment, it's considered to be unbreakable and is a government standard. When you encrypt a file using ccrypt, a password is required. It is best if you continue to use complex passwords for ccrypt encryption because someone might still try.

Using ccrypt is easy enough for encrypting, decrypting, and viewing an encrypted file's contents. I found the rpm on Sourceforge. Be sure to get the 1.11 or later package. Install the ccrypt-1.11 package in the usual way.

$ sudo rpm -i ccrypt-1.11-1.x86_64.rpm

Once installed, you have a few new apps on your system: ccrypt, ccat, ccencrypt, ccdecrypt, and ccguess. The only two actual programs are ccrypt and ccguess. The others are links to ccrypt with their respective options embedded. For example, you can use ccencrypt or ccdecrypt without knowing any ccrypt options for encrypting or decrypting a file. And ccat decrypts and displays the contents of a file without extracting the original file from the encrypted one. The ccguess application can help recover your encryption password if you remember a part of it.

[ Want to learn more about security? Check out the IT security and compliance checklist. ] 


The ccencrypt command encrypts a file using a key (password or passphrase).

$ cat file1.txt
This is a test of the ccrypt utility

$ ccencrypt file1.txt
Enter encryption key: 
Enter encryption key: (repeat)

$ ls

You must enter your encryption key twice to confirm that you know it. Then your file is encrypted and is appended with a .cpt extension. You can copy your encrypted file or move it and it remains encrypted.

cp file1.txt.cpt file2.txt
$ cat file2.txt 
?\?mn???&?ꋄ???n????K?B?^+^?Ҧl?EEn???	?2?u??t?=??=??`ʽ??c
$ file file2.txt 
file2.txt: PGP\011Secret Sub-key -


Issue the ccdecrypt command to decrypt and extract the original file from the encrypted one.

$ ccdecrypt file2.txt 
Enter decryption key: 
$ ls
file1.txt.cpt  file2.txt
$ cat file2.txt
This is a test of the ccrypt utility

Notice that although file2.txt is a copy of file1.txt.cpt, when decrypted it remains file2.txt and does not revert back to file1.txt.


The ccat utility is one of my favorites because it allows me to check the encrypted file contents but doesn't extract the contents.

$ ccat file1.txt.cpt 
Enter decryption key: 
This is a test of the ccrypt utility
$ ls
file1.txt.cpt  file2.txt

The encrypted file, file1.txt.cpt, is left encrypted and intact.


I like the ccguess command but I also hate it. I like it because it can help recover a forgotten key, but I hate it because it could compromise security in the wrong hands. Here's an example of how it works. When I encrypted file1.txt, I used the key goonygoogoo to protect it. Yes, it's not a great password (key), but it's one I'll remember. But if I forget, I might remember that it has the word 'goo' in it. 

ccguess file1.txt.cpt 
Enter approximate key: goo

Generating patterns...1..2..3..4..5..sorting...done.
***g*o 818434604

Possible match: oLK@gw (5 changes, found after trying 6313742182 keys)

As you can see, even a relatively simple key couldn't be cracked even with a prompt that contained a good portion of the key. Could this key stand up to a brute force attack? Probably not, so use long, complex keys or key phrases for added protection.

Wrap up

The ccrypt utility "suite" is an excellent tool for encrypting and decrypting your files. Here you got a small sampling of what the utility can do for you. There are many more options, which you can explore with this one, but these are the ones I've used most. You also got a glimpse of the ccguess utility that might come in handy should you ever need it. Let's hope you don't, especially if you don't remember a large portion of the key.


Topics:   Linux   Linux administration   Security  
Author’s photo

Ken Hess

Ken has used Red Hat Linux since 1996 and has written ebooks, whitepapers, actual books, thousands of exam review questions, and hundreds of articles on open source and other topics. Ken also has 20+ years of experience as an enterprise sysadmin with Unix, Linux, Windows, and Virtualization. More about me

Try Red Hat Enterprise Linux

Download it at no charge from the Red Hat Developer program.