How can I use password protection with the tar command in Linux? I'm new to Linux so please explain to me with simple usage.


As far as I know tar doesn't provide this service. You could use 7zip instead, which does offer encrypted archives.

What you can also do is use gpg in addition to tar:

tar cvJf myarchive.tar.xz myfiles
gpg -c myarchive.tar.xz.gpg

This will give you a password protected archive.

  • hi thanks a lot, can you elaborate a little bit about this command tar cvJf myarchive.tar.xz myfiles gpg -c myarchive.tar.xz.gpg Sorry I'm new to Linux. – kevin Apr 19 '11 at 8:38
  • 1
    You need to read a tutorial on the linux command line. This is basic stuff. – Peltier Apr 19 '11 at 8:47
  • Thanks again !!! Can you point me some good tutorial ? – kevin Apr 19 '11 at 8:59
  • Try this site: gd.tuwien.ac.at/linuxcommand.org – Peltier Apr 19 '11 at 9:11
  • In addition, look at the links of this page: reddit.com/r/Ubuntu/comments/bbnkp/… – Peltier Apr 19 '11 at 9:12

Run the output through pgp

tar .... | pgp --symmetric output.tar.pgp


pgp -d output.tar.gz | tar tv

Consider using proper asymmetric keys (public/private keys) for real protection

  • @sehe - Thanks a lot. But unluckily, I don't understand what you had written. Can you tell me a bit more detail? Thanks !!! – kevin Apr 19 '11 at 8:40
  • 1
    @kevin: To my understanding, a "symmetric key" is a plain-old password-based system, like you're familiar with. An asymmetric key system has two "passwords" or keys, a public and a private one. You can share the public one freely, and people use this to identify you. The private key is the part that proves that you are you, so sharing it is a Bad Thing. Anyhow, the symmetric key is almost certainly what you want, since it's much simpler, although the asymmetric key is more secure, in theory. – bukzor Apr 19 '12 at 15:44

Simple way

Step 1 : sudo apt-get install zip

Step 2 : zip -P password file.zip files

  • the password will show in history of commands . – Mr Coder Apr 30 '20 at 4:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy