How to Encrypt and Decrypt Files using Ccrypt Command

To Encrypt and Decrypt Files using Ccrypt Command

Ccrypt is a command line tool, used to encrypt and decrypt the files and streams in Linux. The encrypted files could not be decrypted without key phrase. Ccrypt standard provides strong security for your encrypted files. Encryption and decryption of linux files using ccrypt command is explained in this article.

Installation of Ccrypt Command

First update the repository by using the following command.

root@linuxhelp:~# apt-get update
Hit http://ppa.launchpad.net wily InRelease                         
Hit http://in.archive.ubuntu.com wily InRelease                     
Hit http://security.ubuntu.com wily-security InRelease
Get:1 http://ppa.launchpad.net wily InRelease [15.5 kB]                
Hit http://in.archive.ubuntu.com wily-updates InRelease                        
Hit http://security.ubuntu.com wily-security/main Sources                                                 
Hit http://in.archive.ubuntu.com wily-backports InRelease                                                      
Hit http://security.ubuntu.com wily-security/restricted Sources                                              
Hit http://ppa.launchpad.net wily/main amd64 Packages                 
Hit http://in.archive.ubuntu.com wily/main Sources                                  
Hit http://security.ubuntu.com wily-security/universe Sources                       
Hit http://ppa.launchpad.net wily/main i386 Packages
.
.
.
Hit http://in.archive.ubuntu.com wily-backports/universe amd64 Packages                                                                                                             
Hit http://in.archive.ubuntu.com wily-backports/multiverse amd64 Packages                                                                                                           
Hit http://in.archive.ubuntu.com wily-backports/main i386 Packages                                                                                                                  
Hit http://in.archive.ubuntu.com wily-backports/restricted i386 Packages                                                                                                            
Hit http://in.archive.ubuntu.com wily-backports/universe i386 Packages                                                                                                              
Hit http://in.archive.ubuntu.com wily-backports/multiverse i386 Packages                                                                                                            
Hit http://in.archive.ubuntu.com wily-backports/main Translation-en                                                                                                                 
Hit http://in.archive.ubuntu.com wily-backports/multiverse Translation-en                                                                                                           
Hit http://in.archive.ubuntu.com wily-backports/restricted Translation-en                                                                                                           
Hit http://in.archive.ubuntu.com wily-backports/universe Translation-en                                                                                                             
Fetched 30.5 kB in 12s (2,372 B/s)                                                                                                                                                  
Reading package lists... Done

Now run the below command to install ccrypt.

root@linuxhelp:~# apt-get install ccrypt
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following NEW packages will be installed:
  ccrypt
0 upgraded, 1 newly installed, 0 to remove and 248 not upgraded.
Need to get 61.0 kB of archives.
After this operation, 267 kB of additional disk space will be used.
Get:1 http://in.archive.ubuntu.com/ubuntu/ wily/universe ccrypt amd64 1.10-4 [61.0 kB]
Fetched 61.0 kB in 0s (77.8 kB/s)
Selecting previously unselected package ccrypt.
(Reading database ... 192189 files and directories currently installed.)
Preparing to unpack .../ccrypt_1.10-4_amd64.deb ...
Unpacking ccrypt (1.10-4) ...
Processing triggers for man-db (2.7.4-1) ...
Setting up ccrypt (1.10-4) ...
ERROR: ccrypt is broken - called emacs-package-install as a new-data-style add-on, but has no compat file.
Install ccrypt for emacs

To Encrypt the File

For encryption, create the sample file and add any content in that file with following command.

root@linuxhelp:~# vim sample
Hi this file is highly confidential.

Here, use the below command to encrypt the file and create a encryption key as well.

root@linuxhelp:~# ccrypt sample
Enter encryption key: 
Enter encryption key: (repeat)

After encryption process, the original file will be saved like sample.cpt.

Now view the encrypted file by using below command.

root@linuxhelp:~# vim sample.cpt 
?6dn?*????????5U?    /??r?d1?' %??D!?n??r?m8?í U?(zl???-n?()z???gWq_?

To Decrypt the file

Run the below command to decrypt the file and also enter the correct key.

root@linuxhelp:~# ccrypt -d sample.cpt 
Enter decryption key:

After the decryption process, view the content by using the below command.

root@linuxhelp:~# vim sample 
Hi this file is highly confidential.

To know more about ccrypt command line, use the below given command.

root@linuxhelp:~# ccrypt --help
Tag : Ccrypt
FAQ
Q
What is Ccrypt?
A
Ccrypt is a command line tool, used to encrypt and decrypt the files and streams in Linux. The encrypted files could not be decrypted without the key phrase. Ccrypt standard provides strong security for your encrypted files.
Q
Is ccrypt platform independent?
A
Yes. Ccrypt works on Linux, Windows, Macintosh OS-X, Unix, Android, and in principle, on many other platforms.
Q
Could you add an option which would make ccrypt create a temporary file (as gzip does), instead of overwriting the original one?
A
This feature of ccrypt was added in release 1.4.
Q
I want to back up encrypted compressed tar files on a remote server, using rsync. But the encryption destroys any similarities in the files so that rsync has to copy the entire file, rather than a compressed one? How to resolve this?
A
A possible solution is to calculate the "diff" of the current backup against the previous one at the local site, and then to store the encrypted compressed "diff" file on the remote server.
Q
I lost a 50MB gzipped file by having a system crash in the middle of decrypting it. Is there any way I can recover my data?
A
If you had a system crash in the middle of encryption or decryption, and no backup copy of your file, you should be able to manually recover most of your data as follows: decrypt the corrupted files with the keys.