How to encrypt a tar file using openssl


In some cases, we may have to send our passwd information to some of your colleagues. Instead of sending them in plain text, you can use tar & openssl combination to encrypt that data. Here is how it can be done.

Encryption :
Tar & gzip the password file and encrypt using openssl des3 and a secret key. Replace the text “secretkey” with your secret password.

[root@alex~]# tar cvzf – passwd_info.txt | openssl des3 -salt -k secretkey | dd of=encrypted_passwd_info
passwd_info.txt
20+1 records in
20+1 records out

The filetype of the encrypted file is “data” and you cannot use “tar -tvzf” to list contents on this.
[root@alex~]# file encrypted_passwd_info
encrypted_passwd_info: data
[root@alex~]# tar tvzf encrypted_passwd_info
gzip: stdin: not in gzip format
tar: Child returned status 1
tar: Error exit delayed from previous errors

Decryption :
While decrypting the file, use the steps below. Replace the text “secretkey” with your secret password which you provided during encryption.

[root@manish ~]# dd if=encrypted_passwd_info |openssl des3 -d -k secretkey |tar xvzf –
20+1 records in
20+1 records out
passwd_info.txt
[root@manish ~]# cat passwd_info.txt | head -1
UNIX User       UNIX Password

About Alex Hunt

Hi All I am Manish Kumar Jha aka Alex Hunt. I am currently working in VMware Software India Pvt Ltd as Operations System Engineer (vCloud Air Operations). I have around 5 Years of IT experience and have exposure on VMware vSphere, vCloud Director, RHEL and modern data center technologies like Cisco UCS and Cisco Nexus 1000v and NSX. If you find any post informational to you please press like and share it across social media and leave your comments if you want to discuss further on any post. Disclaimer: All the information on this website is published in good faith and for general information purpose only. I don’t make any warranties about the completeness, reliability and accuracy of this information. Any action you take upon the information you find on this blog is strictly at your own risk. The Views and opinions published on this blog are my own and not the opinions of my employer or any of the vendors of the product discussed.
This entry was posted in Linux/CentOS. Bookmark the permalink.

One Response to How to encrypt a tar file using openssl

  1. How to encrypt a tar file using openssl | Go Virtual.

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s