The Linux Page

Encrypt zip or PDF file

Hiding keyboard while typing.

Linux has options to encrypt zip or PDF files.

Note that the zip encryption capabilities are not very strong (i.e. they can be easily cracked). So don't use it if you can avoid it and keep in mind that most anyone can see what's inside either way.

zip --encrypt files

Note that there is an option to define the password on the command line (with --password) which is safe if you're the only user on your machine, but not so much on a shared machine since the password will appear in the list of processes.

And the PDF is very similar, but you have to enter the passwords on the command line with that one:

qpdf --encrypt [readpass] [ownerpass] 256 -- \
                                [infile].pdf [outfile].pdf

Another thing about having the password on the command line, it will also appear in your history file. On Ubuntu / bash that would be ~/.bash_history. To fix that issue, you have to edit that file and replace the passwords with whatever you'd like...

The qpdf supports two passwords:

  • readpass — password one can use to read the PDF file.
  • ownerpass — password the owner can use to read or write the PDF file.

Make sure to verify that your file is properly protected before sharing it.