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
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
[root@manish ~]# cat passwd_info.txt | head -1
UNIX User       UNIX Password

Posted in: Linux.
Last Modified: October 31, 2013

One thought on “How to encrypt a tar file using openssl

Leave a reply