PDF files abound on the Internet and at work, and they may contain a password for access. Today, you will learn how to remove a PDF File Password Using the command line. The process is simple, but worth knowing.
Many times, for security reasons, we receive PDF files with a password. One possible reason is to prevent other people from reading the contents of the file. However, if it is a file that you will need to open several times a day, then the best thing to do is to remove the password.
To achieve this, Linux has many tools and especially in the terminal, ideal for streamlining the work and be included in configuration scripts.
In the Linux terminal, there are many options to consider. Each of them has its advantages, but it is necessary to know the password of the PDF file to make everything easier.
1. Remove a PDF File Password with Pdftk
PDFtk is a simple tool for doing everyday things with PDF documents. Among them, you will be able to use it to remove the password from a file that has it. Although it is good to note that this is not the only thing it does, it can also do:
- Add metadata to the file
- Split or rotate pages
- Combine PDF documents
And many other things.
So, first what you have to do is to install it on the system. In the case of Debian, Ubuntu and its derivatives, the process is simple.
sudo apt update sudo apt install pdftk
Then, you can use it in a simple way. All you need to do is follow this syntax.
pdftk /path/to/input.pdf input_pw [password] output out.pdf
As you can see, it is simple. An example of how to use it is as follows.
pdftk /home/imaginelinux/sample.pdf input_pw password123 output out.pdf
So pdftk will take the file, open it with the specified password and then generate another file from it called
This way, you can open the
out.pdf file without using a password.
Remove pdftk on Linux
In case you no longer want to use it, it is best to uninstall it from the system completely.
sudo apt remove pdftk
This will save disk space.
2. Using QPDF to remove a PDF File Password from the terminal
- Splitting and merging files
- Inspecting files for study or analysis.
- Remove known password
If you want to use QPDF, the first thing you have to do is to install it on your system. To achieve this, you can run on Debian, Ubuntu and derivatives:
sudo apt install qpdf
Now to remove the password from the PDF file, you can follow this syntax
qpdf --password=[yourpassword] --decrypt [inputfile.pdf] [output.pdf]
Referring to the example used with pdftk, then it would look like this:
qpdf --password=password123 --decrypt /home/imaginelinux/sample.pdf out.pdf
Just like that, the tool will read the file, and export it in a new one without the password.
Uninstall QPDF from the system
Similarly, if you no longer want to use QPDF, then the best thing to do is to remove it from the system. To achieve this, open a terminal and run.
sudo apt remove qpdf
3. Remove unknown password from a PDF file
In the previous cases, the password was well known to you, but what if you don’t know it? Or if you have forgotten it? All is lost? Well, no. On Linux, you can use a tool to solve this problem.
The tool I am referring to is pdfcrack which performs brute force attacks on the document to find out the password. In this method, you must consider that the process can take a long time, depending on how complex the password is and the resources of your computer.
First install it on Debian, Ubuntu and derivatives:
sudo apt install pdfcrack
Now use it with this syntax
pdfcrack -f [pdf-file]
pdfcrack -f encrypted.pdf
Again, the process can take a long time. However, you can provide a dictionary file to alleviate the time.
pdfcrack -f file.pdf --wordlist=/home/imaginelinux/Documents/passwordsfile.txt
You can also set a minimum and length of the password. Imagine you only remember the size of the password, but what it is. So, you can help the program to do the calculation.
pdfcrack -f encrypted.pdf --minpw=10 --maxpw=21
Or tell the program what are the possible characters used in it.
pdfcrack -f encrypted.pdf --charset="asdfghjkl" --minpw=5 --maxpw=8
All these tricks ease the calculation load of the tool and accelerate the process.
Finally, if you want to remove it from the system, you can run
sudo apt remove pdfcrack
Removing the password from a PDF file is a fairly simple matter to do, but requires specialized tools. Fortunately, on Linux, there are several free ones.
I hope you liked this post and help spread the word through all your networks.