{"id":12545,"date":"2019-03-28T00:06:48","date_gmt":"2019-03-28T00:06:48","guid":{"rendered":"http:\/\/www.appservgrid.com\/paw92\/?p=12545"},"modified":"2019-03-28T00:06:48","modified_gmt":"2019-03-28T00:06:48","slug":"how-to-encrypt-and-decrypt-files-and-directories-using-tar-and-openssl","status":"publish","type":"post","link":"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/03\/28\/how-to-encrypt-and-decrypt-files-and-directories-using-tar-and-openssl\/","title":{"rendered":"How to Encrypt and Decrypt Files and Directories Using Tar and OpenSSL"},"content":{"rendered":"<p>When you have important sensitive data, then its crucial to have an extra layer of security to your files and directories, specially when you need to transmit the data with others over a network.<\/p>\n<p>That\u2019s the reason, I am looking for a utility to encrypt and decrypt certain files and directories in Linux, luckily I found a solution that\u00a0<strong>tar<\/strong>\u00a0with\u00a0<strong>OpenSSL<\/strong>\u00a0can do the trick, yes with the help of these two tools you can easily create and encrypt tar archive file without any hassle.<\/p>\n<p><b>Don\u2019t Miss:<\/b>\u00a0<a href=\"https:\/\/www.tecmint.com\/linux-password-protect-files-with-encryption\/\" target=\"_blank\" rel=\"noopener\">7 Tools to Encrypt and Decrypt Files in Linux<\/a><\/p>\n<p>In this article, we will see how to create and encrypt a\u00a0<strong>tar<\/strong>\u00a0or\u00a0<strong>gz<\/strong>\u00a0(<strong>gzip<\/strong>) archive file with\u00a0<strong>OpenSSL<\/strong>:<\/p>\n<p>Remember that the conventional form of using\u00a0<strong>OpenSSL<\/strong>\u00a0is:<\/p>\n<pre># openssl command command-options arguments\r\n<\/pre>\n<h4>Encrypt Files in Linux<\/h4>\n<p>To encrypt the contents of the current working directory (depending on the size of the files, this may take a while):<\/p>\n<pre># tar -czf - * | openssl enc -e -aes256 -out secured.tar.gz\r\n<\/pre>\n<p>Explanation of the above command:<\/p>\n<ol>\n<li><code>enc<\/code>\u00a0\u2013 openssl command to encode with ciphers<\/li>\n<li><code>-e<\/code>\u00a0\u2013 a enc command option to encrypt the input file, which in this case is the output of the tar command<\/li>\n<li><code>-aes256<\/code>\u00a0\u2013 the encryption cipher<\/li>\n<li><code>-out<\/code>\u00a0\u2013 enc option used to specify the name of the out filename, secured.tar.gz<\/li>\n<\/ol>\n<h4>Decrypt Files in Linux<\/h4>\n<p>To decrypt a tar archive contents, use the following command.<\/p>\n<pre># openssl enc -d -aes256 -in secured.tar.gz | tar xz -C test\r\n<\/pre>\n<p>Explanation of the above command:<\/p>\n<ol>\n<li><code>-d<\/code>\u00a0\u2013 used to decrypt the files<\/li>\n<li><code>-C<\/code>\u00a0\u2013 extract in subdirectory named\u00a0<strong>test<\/strong><\/li>\n<\/ol>\n<p>The following image shows the encryption process and what happens when you try to:<\/p>\n<ol>\n<li>extract the contents of the tarball the traditional way<\/li>\n<li>use the wrong password, and<\/li>\n<li>when you enter the right password<\/li>\n<\/ol>\n<div id=\"attachment_22103\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/08\/Encrypt-Decrypt-Tar-Archive-Files-in-Linux.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-22103\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/08\/Encrypt-Decrypt-Tar-Archive-Files-in-Linux.png\" alt=\"Encrypt or Decrypt Tar Archive File in Linux\" width=\"619\" height=\"500\" aria-describedby=\"caption-attachment-22103\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-22103\" class=\"wp-caption-text\">Encrypt or Decrypt Tar Archive File in Linux<\/p>\n<\/div>\n<p>When you are working on a local network or the Internet, you can always secure your vital documents or files that you share with others by encrypting them, this can help reduce the risk of exposing them to malicious attackers.<\/p>\n<p>We looked at a simple technique of encrypting tarballs using OpenSSL, a openssl command line tool. You can refer to its man page for more information and useful commands.<\/p>\n<p>As usual, for any additional thoughts or simple tips that you wish to share with us, use the feedback form below and in the upcoming tip, we shall look at a way of translating\u00a0<strong>rwx permissions<\/strong>\u00a0into octal form.<\/p>\n<p><a href=\"https:\/\/www.tecmint.com\/encrypt-decrypt-files-tar-openssl-linux\/\" target=\"_blank\" rel=\"noopener\">Source<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>When you have important sensitive data, then its crucial to have an extra layer of security to your files and directories, specially when you need to transmit the data with others over a network. That\u2019s the reason, I am looking for a utility to encrypt and decrypt certain files and directories in Linux, luckily I &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/03\/28\/how-to-encrypt-and-decrypt-files-and-directories-using-tar-and-openssl\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;How to Encrypt and Decrypt Files and Directories Using Tar and OpenSSL&#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-12545","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\/12545","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=12545"}],"version-history":[{"count":1,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/12545\/revisions"}],"predecessor-version":[{"id":12546,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/12545\/revisions\/12546"}],"wp:attachment":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/media?parent=12545"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/categories?post=12545"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/tags?post=12545"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}