HowTo: Linux Remove a PDF File Password Using Command Line Options

I get lots of e-bills (utility, telephone, the Internet, mobile, cable and so on) in a PDF format for my small business, and I need to forward those to my accountant. However, all PDFs files are password protected. I do not want to share my account password with anyone to just open my bills. Evince is a PDF document viewer capable of displaying password protected files, but it cannot remove the password. How do I remove a password from all PDFs under Ubuntu or any other Linux distribution in a batch mode?

You can remove the password using various utilities under Linux. Use any one of the following options:

  1. pdftk – A handy tool for manipulating PDF file.
  2. qpdf – The qpdf program is used to convert one PDF file to another equivalent PDF file.
  3. xpdf-utils – Portable Document Format (PDF) suite — utilities such as pdftops and ps2pdf.
  4. Print to a file – Use Evince software itself.

How Do I Use pdftk To Remove The Password?

Type the following apt-get command to install the pdftk (note it will install java too, if you do not like java, just use another tool):
$ sudo apt-get install pdftk
Decrypt a PDF called input.pdf with YOURPASSWORD-HERE password and create unencrypted output.pdf, enter:

pdftk input.pdf output output.pdf user_pw YOURPASSWORD-HERE

OR

pdftk input.pdf output output.pdf user_pw YOURPASSWORD-HERE owner_pw YOURPASSWORD-HERE

OR

pdftk input.pdf output output.pdf input_pw YOURPASSWORD-HERE

Where,

  • input_pw password : Input PDF owner passwords
  • user_pw password : Input PDF user passwords
  • owner_pw password : Input PDF owner passwords same as input_pw.

How Do I Use qpdf To Remove The Password?

Type the following apt command to install the qpdf:
$ sudo apt-get install qpdf
Decrypt a PDF called input.pdf with YOURPASSWORD-HERE password and create unencrypted output.pdf, enter:

qpdf --password=YOURPASSWORD-HERE --decrypt input.pdf output.pdf

How Do I Use xpdf-utils To Remove The Password?

Type the following command to install the qpdf:
$ sudo apt-get install xpdf-utils
First, decrypt a PDF and create a postscript file, enter:

pdftops -upw YOURPASSWORD-HERE input.pdf

You will get input.ps file. This can be printed or open under Linux itself. But, you can convert it back .ps file (postscript)back to a PDF as follows:

ps2pdf input.ps

Please note that the ps2pdf command is part of ghostscript and it will get installed when you run xpdf-utils.

How Do I Use evince To Remove The Password?

Open a pdf file using evince itself, enter:

evince input.pdf

Enter your password. Once opened click on File > Print > Select “Print to file” > Select “PDF” as output format and click on Print.

Fig.01: PDF file remove password with evince print option

Writing a shell script left as an exercise to the readers.

If You Don’t Know The Password, Use Ghostscript Like This

Update: nickwe pointed out the following command:

gs -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=unencrypted.pdf -c .setpdfwrite -f encrypted.pdf
🐧 If you liked this page, please support my work on Patreon or with a donation.
🐧 Get the latest tutorials on SysAdmin, Linux/Unix, Open Source/DevOps topics:
CategoryList of Unix and Linux commands
File Managementcat
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network Utilitiesdig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
43 comments… add one
  • pdf password remover mac Oct 23, 2012 @ 6:32

    I have many password protected pdf documents, you software help me open them

  • MartinSt Nov 27, 2012 @ 16:33

    I could only remove the password from a file (with probably AES encryption inside) by using MuPDF. No program mentioned above worked with my file.

    mubusy clean -p YOURPASSWORD-HERE input.pdf

    This command generates out.pdf without the password.
    I used a precompiled windows binary from here together with wine:
    http://code.google.com/p/mupdf/downloads/list

    • kostadinovic Dec 2, 2012 @ 21:33

      Same here, I tried all the above solutions.
      Can you tell me some more about your way. I’m running on win7 and I downloaded muPDF but I dont know where to put the command

    • Pete May 30, 2013 @ 9:56

      If you’re using a newer version of MuPDF (I used the git version from AUR), the name of the tool has changed to:
      mutool clean -p YOUR-PASSWORD input.pdf

      Did work for me, cheers!

  • Terry Jan 1, 2013 @ 5:50

    qpdf worked. great description!

  • Marc Mar 23, 2013 @ 16:35

    What about Excel protected File? How can a person recover a lost password for a .xsls file … :(
    (I’m under macOSx If you have a solution with os command line would be great ;) otherwise i’ll just install a dual boot linux)

    Thank you,

  • Kedar Mar 23, 2013 @ 18:17

    Thanks for the tips but here is what I tried (before I came across this site).

    I knew the password, but it was a pain to enter it every single time I tried to open the file. So I just wanted to strip the password and store as a regular PDF. What I did was:
    1. I opened the PDF file in Okular Ver 0.14.3
    2. Go to File -> Print
    3. Print to a PDF file and gave the name of the output file
    I searched everywhere for an option where I could have stripped it of the password, but there was none.
    4. Viola… without anything being done from my side, a new PDF file was created sans the password protection.

    Okular rocks!!!

  • Night Owl Mar 29, 2013 @ 9:50

    Without knowing the password the one line with ghost view worked perfectly! (under Mac OS)

    Thanks!

  • LMM Jan 23, 2014 @ 23:34

    Only problem with the print-to-pdf versions (evince, okular) of this process is that any forms, indexes, links, etc. will be removed.

  • Rhett Fisher Feb 12, 2014 @ 7:47

    It doesn’t work for me:

     gs -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=unencrypted.pdf -c .setpdfwrite -f encrypted.pdf
    **** This file requires a password for access.
    Error: /invalidfileaccess in pdf_process_Encrypt
    Operand stack:
    
    Execution stack:
       %interp_exit   .runexec2   --nostringval--   --nostringval--   --nostringval--   2   %stopped_push   --nostringval--   --nostringval--   --nostringval--   false   1   %stopped_push   1916   1   3   %oparray_pop   1915   1   3   %oparray_pop   1899   1   3   %oparray_pop   --nostringval--   --nostringval--   --nostringval--   --nostringval--   false   1   %stopped_push
    Dictionary stack:
       --dict:1173/1684(ro)(G)--   --dict:1/20(G)--   --dict:82/200(L)--   --dict:82/200(L)--   --dict:113/127(ro)(G)--   --dict:292/300(ro)(G)--   --dict:22/32(L)--
    Current allocation mode is local
    GPL Ghostscript 9.10: Unrecoverable error, exit code 1
    
  • Tommy Mar 14, 2014 @ 19:40

    qpdf worked perfectly. pdftk did not work at all. Thanks for the tips!

  • Amol Mar 31, 2014 @ 8:07

    Thanks for the article.

    pdftk – did not work with user_pw / input_pw / owner_pw.
    pdftops – worked, but lost digital signature of the original pdf.
    qpdf – worked, retained the digital signature, great!

  • Albert May 7, 2014 @ 11:50

    Hi,
    In cygwin (can’t say anything on other platforms), the way you describe pdftk does not work. The command seems not to be in the right order.
    If I do: “pdftk in.pdf output out.pdf input_pw PASSWD”
    I always get: OWNER PASSWORD REQUIRED, but not given (or incorrect)
    However, it works great moving “input_pw PASSWD” just after in.pdf and before output command. I mean:
    pdftk in.pdf input_pw PASSWD output out.pdf
    Works great.
    Hope this helps.

  • David Feb 11, 2015 @ 7:54

    pdftk input.pdf input_pw PASSWORD output output.pdf
    worked for me only if the `input_pw` was before the `output` option

  • Richard Ayotte May 4, 2015 @ 21:35

    I had a weird document that was encrypted without a password. The solution was to decrypt it using qpdf without the password argument.

    qpdf –decrypt input.pdf output.pdf

  • melchi Sep 21, 2015 @ 6:29

    I found it very useful for my airtel bills and some docs from banks.
    the order of parameters matter to pdftk, hence the input_pw should be used before the output command. Otherwise, the tool does not use the password.

    The title is right in my opinion, as that is what came to my mind for googling, when I needed this.

  • Seffent Nov 9, 2015 @ 13:08

    Indeed! For pdftk 2.02 or newer input_pw must be put before output.

  • Andrew P. Feb 23, 2016 @ 23:48

    xpdf-utils 3.02 is a stinker; I would recommend caution before proceeding with installation. On my Ubuntu system, without warning it removed Ghostscript, the Generic CUPS-PDF Printer driver and CUPS, and messed up the backend files for my HP LaserJet, leaving my system with no way of printing anything. Fortunately, when I saw what the xpdf-utils installer had done, I captured the log from the terminal window and saved it as a text file, so I could use it as a guide to restore what xpdf-utils had destroyed. In my opinion, xpdf-utils is an ill-behaved POS that doesn’t belong in any repository. The Xpdf site now shows version 3.04 as the current one, but I wouldn’t bet that the installer is better-behaved than the one I got from the Ubuntu repository.

  • Craig S Mar 24, 2016 @ 16:25

    Found this for bulk removing passwords

    mkdir -p temp && for f in *.pdf ; do qpdf --password=YOURPASSWORDHERE --decrypt "$f" "temp/$f"; done && mv temp/* . && rm -rf temp

Leave a Reply

Your email address will not be published. Required fields are marked *

Use HTML <pre>...</pre>, <code>...</code> and <kbd>...</kbd> for code samples.