How to set password for pdf files?

I need to password protect my PDF file(s), because I am going to send them through email and I want anyone who would view my PDF file(s) to be prompted for a password.

How can I add a password to a PDF in Linux Mint 17.1?

Asked By: David


You can use the program pdftk to set both the owner and/or user password

pdftk input.pdf output output.pdf owner_pw xyz user_pw abc

where owner_pw and user_pw are the commands to add the passwords xyz and abc respectively (you can also specify one or the other but the user_pw is necessary in order to prohibit opening).

You might also want to ensure that encryption strength is 128 bits by adding (though currently 128 bits is default):

.... encrypt_128bit

If you cannot run pdftk as it is no longer in every distro, you can try qpdf. Using qpdf --help gives information on the syntax. Using the same "values" as for pdftk:

qpdf --encrypt abc xyz 256 -- input.pdf output.pdf
Answered By: Anthon

The pdftk toolkit allows for this type of functionality on Linux.

  • open your Ubuntu Terminal CTRL+ALT+T
  • install pdftk by using this command: sudo apt-get install pdftk
  • make sure pdftk is now installed by writing this on the terminal: pdftk. You will see a bunch of pdftk command instructions if it already installed
  • simply use this command to add a password to your existing pdf document: pdftk <source>.pdf output <destination>.pdf userpw <password>


pdftk Mydocs.pdf output Mydocs_pass.pdf userpw secretword

Answered By: dtbnguyen

You can also export an encrypted PDF file from Libre Office (File -> Export as PDF -> Security tab -> Set Passwords -> Set open password), if necessary importing your existing PDF into the Draw program first.

Answered By: James

pdftk depends on old libraries, and so is no longer in the repos of Fedora / CentOS. As a replacement, I prefer qpdf

qpdf --encrypt [readpass] [ownerpass] 256 -- [infile].pdf [outfile].pdf
Answered By: resplin

On Fedora, you can use pdf-stapler to set a password for a PDF file, and also perform other pdftk-like operations.

Example to set the user password (the one required for opening the file):

pdf-stapler -u QRNFFtVXA-8PqF cat input_file.pdf output_file.pdf

This is the password you think of most likely about setting a password to a PDF file.

In case you want to set the owner password (the one that defines permissions like printing, commenting, ect.), use the -o option.

Answered By: Iodnas

Using tools from the Poppler Toolset (from a package like libpoppler or poppler-tools), you can achieve this with a combination of pdftops and ps2pdf.

pdftops in.pdf
ps2pdf -sUserPassword=XXXXX -sOwnerPassword=YYYYY out.pdf

Note that to set a User (view) password, you must set an Owner (edit) password.

Answered By: palswim
Categories: Answers Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.