{"id":12547,"date":"2019-03-28T00:12:25","date_gmt":"2019-03-28T00:12:25","guid":{"rendered":"http:\/\/www.appservgrid.com\/paw92\/?p=12547"},"modified":"2019-03-28T00:12:25","modified_gmt":"2019-03-28T00:12:25","slug":"7-tools-to-encrypt-decrypt-and-password-protect-files-in-linux-2","status":"publish","type":"post","link":"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/03\/28\/7-tools-to-encrypt-decrypt-and-password-protect-files-in-linux-2\/","title":{"rendered":"7 Tools to Encrypt\/Decrypt and Password Protect Files in Linux"},"content":{"rendered":"<p>Encryption is the process of encoding files in such a way that only those who are authorized can access it. Mankind is using encryption from ages even when computers were not in existence. During war they would pass some kind of message that only their tribe or those who are concerned were able to understand.<\/p>\n<p>Linux distribution provides a few standard encryption\/decryption tools that can prove to be handy at times. Here in this article we have covered 7 such tools with proper standard examples, which will help you to encrypt, decrypt and password protect your files.<\/p>\n<p>If you are interested in knowing how to generate Random password in Linux as well as creating random password you may like to visit the below link:<\/p>\n<p><a title=\"Create Random Passwords in Linux\" href=\"https:\/\/www.tecmint.com\/generate-encrypt-decrypt-random-passwords-in-linux\/\" target=\"_blank\" rel=\"noopener\">Generate\/Encrypt\/Decrypt Random Passwords in Linux<\/a><\/p>\n<h3>1. GnuPG<\/h3>\n<p><strong>GnuPG<\/strong>\u00a0stands for\u00a0<strong>GNU Privacy Guard<\/strong>\u00a0and is often called as\u00a0<strong>GPG<\/strong>\u00a0which is a collection of cryptographic software. Written by GNU Project in C programming Language. Latest stable release is\u00a0<strong>2.0.27<\/strong>.<\/p>\n<p>In most of the today\u2019s Linux distributions, the gnupg package comes by default, if in-case it\u2019s not installed you may\u00a0<strong>apt<\/strong>\u00a0or\u00a0<strong>yum<\/strong>\u00a0it from repository.<\/p>\n<pre>$ sudo apt-get install gnupg\r\n# yum install gnupg\r\n<\/pre>\n<p>We have a text file (<strong>tecmint.txt<\/strong>) located at\u00a0<strong>~\/Desktop\/Tecmint\/<\/strong>, which will be used in the examples that follows this article.<\/p>\n<p>Before moving further, check the content of the text file.<\/p>\n<pre>$ cat ~\/Desktop\/Tecmint\/tecmint.txt\r\n<\/pre>\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/03\/Check-Content-of-File.gif\"><img decoding=\"async\" class=\"size-medium wp-image-12281\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/03\/Check-Content-of-File.gif\" alt=\"Check Content of File\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p>Now encrypt\u00a0<strong>tecmint.txt<\/strong>\u00a0file using gpg. As soon as you run the gpc command with option\u00a0<strong>-c<\/strong>\u00a0(encryption only with symmetric cipher) it will create a file\u00a0<strong>texmint.txt.gpg<\/strong>. You may list the content of the directory to verify.<\/p>\n<pre>$ gpg -c ~\/Desktop\/Tecmint\/tecmint.txt\r\n$ ls -l ~\/Desktop\/Tecmint\r\n<\/pre>\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/03\/Encrypt-File.gif\"><img decoding=\"async\" class=\"size-medium wp-image-12282\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/03\/Encrypt-File.gif\" alt=\"Encrypt File in Linux\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p><strong>Note<\/strong>: Enter\u00a0<strong>Paraphrase<\/strong>\u00a0twice to encrypt the given file. The above encryption was done with\u00a0<strong>CAST5<\/strong>\u00a0encryption algorithm automatically. You may specify a different algorithm optionally.<\/p>\n<p>To see all the encryption algorithm present you may fire.<\/p>\n<pre>$ gpg --version\r\n<\/pre>\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/03\/Check-Encryption-Algorithm.gif\"><img decoding=\"async\" class=\"size-medium wp-image-12283\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/03\/Check-Encryption-Algorithm.gif\" alt=\"Check Encryption Algorithm\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p>Now, if you want to decrypt the above encrypted file, you may use the following command, but before we start decrypting we will first remove the original file i.e.,\u00a0<strong>tecmint.txt<\/strong>\u00a0and leave the encrypted file\u00a0<strong>tecmint.txt.gpg<\/strong>untouched.<\/p>\n<pre>$ rm ~\/Desktop\/Tecmint\/tecmint.txt\r\n$ gpg ~\/Desktop\/Tecmint\/tecmint.txt.gpg\r\n<\/pre>\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/03\/Decrypt-File.gif\"><img decoding=\"async\" class=\"size-medium wp-image-12284\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/03\/Decrypt-File.gif\" alt=\"Decrypt File in Linux\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p><strong>Note<\/strong>: You need to provide the same password you gave at encryption to decrypt when prompted.<\/p>\n<h3>2. bcrypt<\/h3>\n<p><strong>bcrypt<\/strong>\u00a0is a key derivation function which is based upon Blowfish cipher. Blowfish cipher is not recommended since the time it was figured that the cipher algorithm can be attacked.<\/p>\n<p>If you have not installed\u00a0<strong>bcrypt<\/strong>, you may\u00a0<strong>apt<\/strong>\u00a0or\u00a0<strong>yum<\/strong>\u00a0the required package.<\/p>\n<pre>$ sudo apt-get install bcrypt\r\n# yum install bcrypt\r\n<\/pre>\n<p>Encrypt the file using bcrypt.<\/p>\n<pre>$ bcrypt ~\/Desktop\/Tecmint\/tecmint.txt\r\n<\/pre>\n<p>As soon as you fire the above command, a new file name\u00a0<strong>texmint.txt.bfe<\/strong>\u00a0is created and original file\u00a0<strong>tecmint.txt<\/strong>gets replaced.<\/p>\n<p>Decrypt the file using bcrypt.<\/p>\n<pre>$ bcrypt tecmint.txt.bfe\r\n<\/pre>\n<p><strong>Note<\/strong>: bcrypt do not has a secure form of encryption and hence it\u2019s support has been disabled at least on Debian Jessie.<\/p>\n<h3>3. ccrypt<\/h3>\n<p>Designed as a replacement of UNIX crypt, ccrypt is an utility for files and streams encryption and decryption. It uses Rijndael cypher.<\/p>\n<p>If you have not installed ccrypt you may apt or yum it.<\/p>\n<pre>$ sudo apt-get install ccrypt\r\n# yum install ccrypt\r\n<\/pre>\n<p>Encrypt a file using ccrypt. It uses\u00a0<strong>ccencrypt<\/strong>\u00a0to encrypt and\u00a0<strong>ccdecrypt<\/strong>\u00a0to decrypt. It is important to notice that at encryption, the original file (<strong>tecmint.txt<\/strong>) is replaced by (<strong>tecmint.txt.cpt<\/strong>) and at decryption the encrypted file (<strong>tecmint.txt.cpt<\/strong>) is replaced by original file (<strong>tecmint.txt<\/strong>). You may like to use\u00a0<strong>ls<\/strong>\u00a0command to check this.<\/p>\n<p>Encrypt a file.<\/p>\n<pre>$ ccencrypt ~\/Desktop\/Tecmint\/tecmint.txt\r\n<\/pre>\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/03\/ccencrypt-file.gif\"><img decoding=\"async\" class=\"size-medium wp-image-12286\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/03\/ccencrypt-file.gif\" alt=\"ccencrypt File in Linux\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p>Decrypt a file.<\/p>\n<pre>$ ccdecrypt ~\/Desktop\/Tecmint\/tecmint.txt.cpt\r\n<\/pre>\n<p>Provide the same password you gave during encryption to decrypt.<\/p>\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/03\/ccdecrypt-File.gif\"><img decoding=\"async\" class=\"size-medium wp-image-12287\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/03\/ccdecrypt-File.gif\" alt=\"ccdecrypt File in Linux\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<h3>4. Zip<\/h3>\n<p>It is one of the most famous archive format and it is so much famous that we generally call archive files as zip files in day-to-day communication. It uses pkzip stream cipher algorithm.<\/p>\n<p>If you have not installed zip you may like to apt or yum it.<\/p>\n<pre>$ sudo apt-get install zip\r\n# yum install zip\r\n<\/pre>\n<p>Create a encrypted zip file (several files grouped together) using zip.<\/p>\n<pre>$ zip --password mypassword tecmint.zip tecmint.txt tecmint1.1txt tecmint2.txt<\/pre>\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/03\/Create-Encrypt-Zip-File.gif\"><img decoding=\"async\" class=\"size-medium wp-image-12288\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/03\/Create-Encrypt-Zip-File.gif\" alt=\"Create Encrypt Zip File\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p>Here\u00a0<strong>mypassword<\/strong>\u00a0is the password used to encrypt it. A archive is created with the name\u00a0<strong>tecmint.zip<\/strong>\u00a0with zipped files\u00a0<strong>tecmint.txt<\/strong>,\u00a0<strong>tecmint1.txt<\/strong>\u00a0and\u00a0<strong>tecmint2.txt<\/strong>.<\/p>\n<p>Decrypt the password protected zipped file using unzip.<\/p>\n<pre>$ unzip tecmint.zip\r\n<\/pre>\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/03\/Decrypt-Zip-File.gif\"><img decoding=\"async\" class=\"size-medium wp-image-12289\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/03\/Decrypt-Zip-File.gif\" alt=\"Decrypt Zip File\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p>You need to provide the same password you provided at encryption.<\/p>\n<h3>5. Openssl<\/h3>\n<p><strong>Openssl<\/strong>\u00a0is a command line cryptographic toolkit which can be used to encrypt message as well as files.<\/p>\n<p>You may like to install openssl, if it is not already installed.<\/p>\n<pre>$ sudo apt-get install openssl\r\n# yum install openssl\r\n<\/pre>\n<p>Encrypt a file using openssl encryption.<\/p>\n<pre>$ openssl enc -aes-256-cbc -in ~\/Desktop\/Tecmint\/tecmint.txt -out ~\/Desktop\/Tecmint\/tecmint.dat\r\n<\/pre>\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/03\/Encrypt-File-Using-Openssl.gif\"><img decoding=\"async\" class=\"size-medium wp-image-12290\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/03\/Encrypt-File-Using-Openssl.gif\" alt=\"Encrypt File Using Openssl\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p>Explanation of each option used in the above command.<\/p>\n<ol>\n<li><strong>enc<\/strong>\u00a0: encryption<\/li>\n<li><strong>-aes-256-cbc<\/strong>\u00a0: the algorithm to be used.<\/li>\n<li><strong>-in<\/strong>\u00a0: full path of file to be encrypted.<\/li>\n<li><strong>-out<\/strong>\u00a0: full path where it will be decrypted.<\/li>\n<\/ol>\n<p>Decrypt a file using openssl.<\/p>\n<pre>$ openssl enc -aes-256-cbc -d -in ~\/Desktop\/Tecmint\/tecmint.dat &gt; ~\/Desktop\/Tecmint\/tecmint1.txt\r\n<\/pre>\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/03\/Decrypt-File-Using-Openssl.gif\"><img decoding=\"async\" class=\"size-medium wp-image-12291\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/03\/Decrypt-File-Using-Openssl.gif\" alt=\"Decrypt File Using Openssl\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<h3>6. 7-zip<\/h3>\n<p>The very famous open source 7-zip archiver written in C++ and able to compress and uncompress most of the known archive file format.<\/p>\n<p>If you have not installed 7-zip you may like to apt or yum it.<\/p>\n<pre>$ sudo apt-get install p7zip-full\r\n# yum install p7zip-full\r\n<\/pre>\n<p>Compress files into zip using 7-zip and encrypt it.<\/p>\n<pre>$ 7za a -tzip -p -mem=AES256 tecmint.zip tecmint.txt tecmint1.txt\r\n<\/pre>\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/03\/Compress-File-Using-7Zip.gif\"><img decoding=\"async\" class=\"size-medium wp-image-12292\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/03\/Compress-File-Using-7Zip.gif\" alt=\"Compress File Using 7-Zip\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p>Decompress encrypted zip file using 7-zip.<\/p>\n<pre>$ 7za e tecmint.zip\r\n<\/pre>\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/03\/Decrypt-File-Using-7-Zip.gif\"><img decoding=\"async\" class=\"size-medium wp-image-12293\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/03\/Decrypt-File-Using-7-Zip.gif\" alt=\"Decrypt File Using 7-Zip\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p><strong>Note<\/strong>: Provide same password throughout in encryption and decryption process when prompted.<\/p>\n<p>All the tools we have used till now are command based. There is a GUI based encryption tool provided by nautilus, which will help you to encrypt\/decrypt files using Graphical interface.<\/p>\n<h3>7. Nautilus Encryption Utility<\/h3>\n<p>Steps to encrypt files in GUI using Nautilus encryption utility.<\/p>\n<h6>Encryption of file in GUI<\/h6>\n<p><strong>1.<\/strong>\u00a0Right click the file you want to encrypt.<\/p>\n<p><strong>2.<\/strong>\u00a0Select format to zip and provide location to save. Provide password to encrypt as well.<\/p>\n<div id=\"attachment_12294\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/03\/Encrypt-File-Using-Nautilus.jpeg\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-12294\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/03\/Encrypt-File-Using-Nautilus-620x392.jpeg\" sizes=\"auto, (max-width: 620px) 100vw, 620px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/03\/Encrypt-File-Using-Nautilus-620x392.jpeg 620w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/03\/Encrypt-File-Using-Nautilus.jpeg 785w\" alt=\"Encrypt File Using Nautilus\" width=\"620\" height=\"392\" aria-describedby=\"caption-attachment-12294\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-12294\" class=\"wp-caption-text\">Encrypt File Using Nautilus<\/p>\n<\/div>\n<p><strong>3.<\/strong>\u00a0Notice the message \u2013 encrypted zip created successfully.<\/p>\n<div id=\"attachment_12296\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/03\/Ecrypted-Zip-File.jpeg\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-12296\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/03\/Ecrypted-Zip-File-620x344.jpeg\" sizes=\"auto, (max-width: 620px) 100vw, 620px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/03\/Ecrypted-Zip-File-620x344.jpeg 620w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/03\/Ecrypted-Zip-File.jpeg 645w\" alt=\"Encrypted Zip File Confirmation\" width=\"620\" height=\"344\" aria-describedby=\"caption-attachment-12296\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-12296\" class=\"wp-caption-text\">Encrypted Zip File Confirmation<\/p>\n<\/div>\n<h6>Decryption of file in GUI<\/h6>\n<p><strong>1.<\/strong>\u00a0Try opening the zip in GUI. Notice the\u00a0<strong>LOCK-ICON<\/strong>\u00a0next to file. It will prompt for password, Enter it.<\/p>\n<div id=\"attachment_12297\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/03\/Decryption-of-File.jpeg\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-12297\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/03\/Decryption-of-File.jpeg\" alt=\"Decryption of File\" width=\"553\" height=\"431\" aria-describedby=\"caption-attachment-12297\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-12297\" class=\"wp-caption-text\">Decryption of File<\/p>\n<\/div>\n<p><strong>2.<\/strong>\u00a0When successful, it will open the file for you.<\/p>\n<div id=\"attachment_12298\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/03\/Uncompressed-Files.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-12298\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/03\/Uncompressed-Files-620x349.jpg\" sizes=\"auto, (max-width: 620px) 100vw, 620px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/03\/Uncompressed-Files-620x349.jpg 620w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/03\/Uncompressed-Files-1024x576.jpg 1024w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/03\/Uncompressed-Files.jpg 1366w\" alt=\"Decryption Confirmation\" width=\"620\" height=\"349\" aria-describedby=\"caption-attachment-12298\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-12298\" class=\"wp-caption-text\">Decryption Confirmation<\/p>\n<\/div>\n<p>That\u2019s all for now. I\u2019ll be here again with another interesting topic. Till then stay tuned and connected to Tecmint. Don\u2019t forget to provide us with your valuable feedback in the comments below. Like and share us and help us get spread.<\/p>\n<p><a href=\"https:\/\/www.tecmint.com\/linux-password-protect-files-with-encryption\/\" target=\"_blank\" rel=\"noopener\">Source<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Encryption is the process of encoding files in such a way that only those who are authorized can access it. Mankind is using encryption from ages even when computers were not in existence. During war they would pass some kind of message that only their tribe or those who are concerned were able to understand. &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/03\/28\/7-tools-to-encrypt-decrypt-and-password-protect-files-in-linux-2\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;7 Tools to Encrypt\/Decrypt and Password Protect Files in Linux&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-12547","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/12547","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/comments?post=12547"}],"version-history":[{"count":1,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/12547\/revisions"}],"predecessor-version":[{"id":12548,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/12547\/revisions\/12548"}],"wp:attachment":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/media?parent=12547"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/categories?post=12547"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/tags?post=12547"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}