How to Encrypt Files from Command line with ccrypt

How to Encrypt Files from Command line with ccrypt

Linux have suitable number of tools that make file encrypting fast and smooth. But there’s only few available that work in command line only. The encrypting tool without gui is the best in server environments where you can include… also why not for desktop if you’re just like me who uses more terminal than other programs. The one of the best picks that I’ve found is Ccrypt.

Why you Should use Encryption?

Encryption is process that changes information in such a way as to make it unreadable by anyone without knowing the special opening key. You can easily to encrypt or decrypt your files with it and it takes small effort to use it. Also it won’t hog your system resources since it will only use small portion of your hardware resources.

Ccrypt command line tool for encrypting and decrypting your files

Ccrypt’s main function is to encrypt and decrypt files. It’s technology is based on the U.S. government’s beloved Advanced Encryption Standard also known as AES. This standard provides strong security for your encrypted files.

To install it you’ve to type in terminal:
sudo apt-get install ccrypt

You can simply encrypt your file with this example shown below:
ccrypt movie.avi
and after that it will prompt the key you would like to use as password, which will be used again when you want to decrypt the file.

To decrypt the file you have to type this:
ccrypt -d movie.avi

Also you can encrypt folder recursively:
ccrypt -r foldername

With this command you can print the file content straight in the terminal without need to decrypt it but of course the passphrase is needed to read it. This command works just fine with text or similar kinda file formats.
ccrypt -c test.txt

How to use key-file and increase the security of your encrypted files

In ccrypt you can also use key-file option which is totally up to you if you want to use it or not. Key-file can be a very long password saved in text file. This can give extra security, makes it easier to share with friends and you don’t have to remember the password itself, only thing that you have to keep in safe is the file itself.

How to actually use the key-file feature? Let’s say you wanted encrypt a file with using a key-file rather than using password.
In this example we’re using files “keyfile.txt” and mp3 file called “sound8.mp3”. The first file includes the password and second file is which we want to encrypt.
Type the following command:
ccrypt -K keyfile.txt sound8.mp3

Original file will be deleted and it will be replaced by .cpt file which is the format for the encrypted file.

To decrypt the file, use following command to decrypt and when it prompts for the password just add the filename or path to the file:
ccrypt -d sound8.mp3.cpt
And voilà your file is decrypted and back to normal.

How to change password without decrypting the file itself

So how can you change the password or the key-file without decrypting the file and then encrypting it again with new password? Ccrypt have attribute “-x” which you can use against encrypted file. Type:
ccrypt -x sound8.mp3.cpt
It will prompt about old password first. After that you have to enter the password or the key-file path twice.

Conclusion
Although encrypting your files won’t save your data from theft or losing your stuff, but you will be sure that the stuff won’t end up in wrong hands.
Some idea's what you could do with this encryption tool:

  • Creating scripts based on this (if you’re sysop just like me)
  • Encrypting your backups and photos


Do you know good encryption tool(s) that are similar to ccrypt? Please leave comment below and let us know!