Password-protect a PDF with qpdf
Encrypt a PDF with a user and owner password (AES-256) from the command line.
Run qpdf --encrypt owner-pass user-pass 256 -- input.pdf output.pdf — user-pass is what readers must type to open it.
01Command
Command
$ qpdf --encrypt owner-pass user-pass 256 -- input.pdf output.pdf02What it does
qpdf's --encrypt sets two passwords: the user password (needed to open the file) and the owner password (needed to change permissions). 256 selects AES-256, the strongest option. Extra flags between the key length and -- control restrictions: --modify=none blocks editing and --extract=n blocks copying text. To remove protection, qpdf --decrypt with the password writes a plain copy.
03Risk
!Warning: If you forget both passwords the PDF is effectively unrecoverable — qpdf is not a password cracker. The -- separator is required before the input file. Recipients on very old readers may need the weaker 128-bit option instead of 256.
04Undo
Undo
$ qpdf --decrypt --password=user-pass output.pdf decrypted.pdf05Sources
- qpdf(1) - PDF transformation softwareEvidence: qpdf --encrypt user-password owner-password key-length [options] -- infile outfile adds encryption; --decrypt removes it with the correct password.
- qpdf: Encryption — official documentationEvidence: Documents user vs owner passwords, 256-bit AES encryption and restrictions such as --modify=none and --extract=n.
Last verified: 2026-09-18 · Category: Media