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

by on January 13, 2010 · 37 comments· LAST UPDATED January 21, 2010

in , ,

I get lots of e-bills (utility, telephone, 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 don't 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 option:

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


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


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


  • 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 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 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:


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

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
Tweet itFacebook itG+ itDownload PDF versionFound an error/typo on this page?

{ 37 comments… read them below or add one }

1 M.M January 13, 2010 at 10:17 am

You didn’t “Remove” the password, you just change it and only because you know the owner password. If I send you a pdf with my password you’ll not be able to change anything, maybe you should change you’re title to “Linux Update a PDF File Password Using Command Line Options”


2 D January 13, 2010 at 11:11 am

M.M is right.


3 rahul January 13, 2010 at 11:57 am

Very well written and overcome lots of irritating passwords. Very good note.


4 nickwe January 13, 2010 at 4:33 pm

If you don’t know the password, use Ghostscript like this:

gs -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=unencrypted.pdf -c .setpdfwrite -f encrypted.pdf



Edited by admin – added code tags.


5 John April 23, 2010 at 8:09 pm

that gs command on linux doesnt work with certain PDFs… wherease those some PDFs are correctly de-crypted with that command on Windows.
Does an alternative method exist for removing protections from PDFs on linux ?

thank you


6 Julio February 10, 2012 at 5:38 pm

Thank you very much… your help is highly appreciated


7 Greg January 17, 2010 at 6:00 pm

You could just ‘print’ the file to postscript, and then use ps2pdf to make a new pdf.


8 meho_r January 21, 2010 at 7:53 pm

Thanks a lot, Nicolas, that worked perfectly :-)


9 fiox April 18, 2010 at 8:43 pm

Very Very Good


10 Nilesh May 27, 2010 at 3:08 pm

The ghostscript command does not work :(
[nilesh@Linux Nilesh]$ gs -q -dBATCH -dNOPAUSE -sDEVICE=pdfwrite -sOutputFile=unencrypted.pdf -c .setpdfwrite -f /home/nilesh/1.10532926.pdf
**** This file requires a password for access.
**** The file was produced by:
**** >>>> [ReportSuite Version 6.0.0] on AIX <<<<
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 1878 1 3 %oparray_pop 1877 1 3 %oparray_pop 1861 1 3 %oparray_pop –nostringval– –nostringval– –nostringval– –nostringval– false 1 %stopped_push
Dictionary stack:
–dict:1151/1684(ro)(G)– –dict:1/20(G)– –dict:75/200(L)– –dict:75/200(L)– –dict:108/127(ro)(G)– –dict:288/300(ro)(G)– –dict:18/25(L)–
Current allocation mode is local
GPL Ghostscript 8.71: Unrecoverable error, exit code 1


11 el_ingeniero July 23, 2010 at 12:39 am

the ghostscript command doesn’t seem to work on forms. The file gets decrypted ok, but the form fields get stripped out.


12 Denilson Figueiredo de Sá September 20, 2010 at 8:35 am

In my case, I knew the User-password (although I didn’t know the Owner-password). Here is my experience when using these tools:

pdftk – It requires the Owner-password.
qpdf – Worked perfectly!
xpdf-utils – I’d like to avoid PDF -> PS -> PDF, as it could increase the file size and maybe lose some PDF features.
Print to a file (using Evince) – It works, but the final PDF was 3 (or more) times larger than the original.

So, the best solution for me was qpdf, as it converted a PDF directly to another PDF, kept the file size almost the same as the original (in fact, it shrunk a little), and it worked fine with the only password I had.


13 Misha October 9, 2010 at 9:13 pm

> pdftk – It requires the Owner-password.
> qpdf – Worked perfectly!

same for me, including

>the best solution for me was qpdf, as it converted a PDF directly to another PDF,
>kept the file size almost the same as the original

in my case there was a very small increase of a file size, 5.38 Mb (encrypted) -> 5.40 Mb (decrypted).


14 martin alexander October 23, 2010 at 1:42 am

martin writes: Hi Denilson — I enjoy your blog very much , but now I have a question of different sort ; my friends from Poland just went to Rio for 10 months to keep their 15 year old daughter away from bad influences in Warsaw , – they took an Asus EEE PC 120 A comp with them but forgot to pack the powering cable with them … so now they are in Rio and can’t charge up their comp . I will try to locate their cable and ship it to them but at the same time I was curious that perhaps you ( being in Rio) may suggest some better solution for them (shipping takes quite a long time ) –I would appreciate very much any of your thoughts on that matter — my email is ; best wishes –yours truly –martin alexander


15 Travis December 29, 2010 at 12:05 am

evince isn’t a true command line option as it requires X and my servers don’t have X so not even a viable solution. I also agree with MM as I don’t have the passwords to the documents I’ve been sent but still need to read the PDFs to place in the correct place on our servers and none of these options provide a solution.


16 robert January 1, 2011 at 6:24 pm


Thank you very much for this useful infos.
Nickwe comment is working for me.
(gs -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=unencrypted.pdf -c .setpdfwrite -f encrypted.pdf)



17 datt March 31, 2011 at 2:32 pm

i used command called CAT > telnet.pdf after using this command my entire pdf file are not opening what do i do now? please any one can help me out….


18 RAMI June 15, 2011 at 2:22 pm

I want to open some pdf file which are locked from opening can i use the command line in window os.


19 Scott May 14, 2012 at 9:32 pm

I was looking to install qpdf on Centos, but yum install wouldn’t do it. I had to use the following to get it installed.

Download qpdf source from
yum install zlib pcre zlib-devel pcre-devel
make install


20 Rangi November 27, 2012 at 7:26 am

Worked for me on Red Hat, thanks!


21 UserLinux June 17, 2012 at 6:13 pm

Thanks a lot!!
$ gs -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=unencrypted.pdf -c .setpdfwrite -f encrypted.pdf
it worked! I only waited 10 or 12 minutes!


22 cborlee July 19, 2012 at 4:46 am

I made some test.
1. If the encrypted pdf file set an “file open” password, and you don’t know the password. Then neither pdftk, qpdf nor gs can decrypt the pdf.
2. If you know either owner or user password, you can decrypt the pdf with qpdf. Though there may have som error message. The idea is that you can open and show the content first.
3. ghostscript method is great! and I use it on win32, find gs for win32 on (gs905w32.exe 2012-7-19), download and install
4.set path for gs, (computer->mouse right click->content->advanced system setup->environment->user variable->add or edit->add path “C:\Program Files\gs\gs9.05\bin”

want a batch convert on win32? try this
1.copy all encrypted pdf files into a working directory, and create a sub directory named conv cmd mode, in this directory type(in quote”): “dir *.pdf /b >conv.txt”
3.create a batch file :conv.bat content as
FOR /F “eol=; usebackq delims==” %%i in (conv.txt) do gswin32c -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=conv/%%i -c .setpdfwrite -f %%i cmd mode, in this dir type: “conv”
5.done! all decrypted files will be sent into sub dir”conv”


23 annaanan October 23, 2012 at 6:31 am

I have a lots of protected pdf files, with your tool, I success open these documents


24 pdf password remover mac October 23, 2012 at 6:32 am

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


25 MartinSt November 27, 2012 at 4:33 pm

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:


26 kostadinovic December 2, 2012 at 9:33 pm

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


27 Pete May 30, 2013 at 9:56 am

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!


28 Terry January 1, 2013 at 5:50 am

qpdf worked. great description!


29 Marc March 23, 2013 at 4:35 pm

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,


30 Kedar March 23, 2013 at 6:17 pm

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


31 Night Owl March 29, 2013 at 9:50 am

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



32 LMM January 23, 2014 at 11:34 pm

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


33 Rhett Fisher February 12, 2014 at 7:47 am

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


34 Tommy March 14, 2014 at 7:40 pm

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


35 Amol March 31, 2014 at 8:07 am

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!


36 Albert May 7, 2014 at 11:50 am

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.


37 David February 11, 2015 at 7:54 am

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


Leave a Comment

Tagged as: , , , , , , , , , , , , , , , , , , , , ,

Previous Faq:

Next Faq: