Linux Programmer | RHCE | RHCSA

Search This Blog

Create Password Protected .tar file in linux.

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.
use "gpg" for creating password protected .tar
1. tar Creation
tar czvpf - /path/tp/directory | gpg --symmetric --cipher-algo aes256 -o myarchive.tar.gz.gpg
this will ask for the password
enter password:
repeat password:
Once you have entred the password then it will start the process.

Extract .tar file.
gpg -d  myarchive.tar.gz.gpg | tar xzvf -

it will ask for the password. once you entered correct password it will start extracting process.

Unlock it .tar with key file 
1. tar czvpf - /path/tp/directory | gpg --symmetric --cipher-algo aes256 -o myarchive.tar.gz.gpg
enter paraphrase key
store this paraphrase key into some file . for e.g. /$HOME/passkey.pem
2. Extract tar with key file
gpg -d --passphrase `cat /path/to/keyfile/passkey.pem` myarchive.tar.gz.gpg | tar xzvf -

No comments:

Post a Comment

Kubernetes Cluster Security - Starting 2026 the Right Way 🛡️

Sooooo finally writing the first blog of 2026 — and what better topic to kick things off than Kubernetes cluster security . Kubernetes has...