18

I use tar -czf test.tar.gz test/ to compress test forlder to test.tar.gz . Now, I want compress to test.tar.gz with password "mypass" How can I do?

bitmask
  • 32,434
  • 14
  • 99
  • 159
abent
  • 309
  • 1
  • 2
  • 7
  • 1
    https://superuser.com/questions/162624/how-to-password-protect-gzip-files-on-the-command-line – Denis Apr 06 '19 at 13:46

1 Answers1

29

Neither the tar format nor the gz format has built-in support for password-protecting files.
Use crypt or gpg on the
Refer this encrypt-and-decrypt-files-with-a-password for more info.

tar cvvjf - /path/to/files | ccrypt > backup.tar.bz2.cpt

or

ccrypt backup.tar.bz2

And then to decrypt:

cat ../backup.tar.bz2 | ccrypt -d | tar -xjf -

You can also use zip

zip -e file.zip file

Will ask you on a prompt for a password. It is more secure then passing the password via the command line via zip -P password.

falsePockets
  • 3,826
  • 4
  • 18
  • 37
Santosh A
  • 5,173
  • 27
  • 37