How to set password for pdf files?

53,449

Solution 1

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 also might want to override the default 40 bit encryption strength by adding:

.... 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

Solution 2

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

Solution 3

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>

Example:

pdftk Mydocs.pdf output Mydocs_pass.pdf userpw secretword

http://wildabdat.tumblr.com/post/13245065154/how-to-add-password-to-your-pdf-docs-on-ubuntu

Solution 4

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.

Solution 5

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 out.ps
ps2pdf -sUserPassword=XXXXX -sOwnerPassword=YYYYY out.ps out.pdf

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

Share:
53,449

Related videos on Youtube

rufus1530
Author by

rufus1530

Updated on September 18, 2022

Comments

  • rufus1530
    rufus1530 over 1 year

    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?

  • David Braverman
    David Braverman almost 9 years
    Default is 128 bit encryption (at least in pdftk 2.02-2).
  • Ondra Žižka
    Ondra Žižka almost 6 years
    I used Docker to overcome. askubuntu.com/questions/1028522/…
  • gloschtla
    gloschtla over 4 years
    opening the non-encrypted PDF in LibreOffice Writer didn't work for me.
  • gloschtla
    gloschtla over 4 years
    It seems that Evince (document reader) version 3.18.2 can only open PDFs which I encrypted with 128 instead of 256.
  • Bryce Stampfl
    Bryce Stampfl over 4 years
    What about LibreOffice Draw, @gloschtla?
  • bananabrann
    bananabrann over 4 years
    Note: For idiots like me, you have to actually type "output"
  • Alexis Wilke
    Alexis Wilke about 3 years
    @gloschtla I used 256 and evince worked as expected. I'm still on Bionic, though (Ubuntu 18.04). Hopefully evince didn't go backward in newer versions.