How to Add and Remove Passwords from PDF Files on Linux

Linux TLDR
Last Updated:
Reading time: 3 minutes

PDFs are the primary file format for sharing sensitive educational, government, or office documents with individuals, often encrypted with a password to prevent unauthorized access. However, with a valid password, individuals can easily decrypt and store them in an encrypted wallet for future access.

But to share this file further, you’ll need to share the password, which often contains sensitive information like usernames, identification numbers, birthdates, etc. In such scenarios, you can decrypt the file and re-encrypt it with a new password.

In this article, you are about to learn how to add and remove passwords from PDF files on Linux.

How to Add and Remove Passwords from PDF Files on Linux

There are multiple ways to add (encrypt) and remove (decrypt) PDF files on Linux, but today we will focus on two popular CLI tools named PDFtk and QPDF. Don’t forget to read the entire article to find out the bonus tip for removing PDF file passwords without any external tool.

Method 1: Add and Remove Password Using PDFtk

PDFtk is a popular command-line utility for manipulating Portable Document Formats (PDFs), such as joining or splitting PDFs, pulling single pages from a file, encrypting and decrypting PDF files, adding, updating, and exporting a PDF’s metadata, exporting bookmarks to a text file, and adding or removing attachments to a PDF, among many other functions.

Another good aspect of this tool is that it’s free and available for Linux, Windows, and macOS, whereas Linux users can easily install it from the distribution’s default package manager.

#On Debian, Ubuntu, Mint, Pop!_OS, etc.
$ sudo apt install pdftk

#On RedHat, Fedora, AlmaLinux, CentOS, etc.
$ sudo dnf install pdftk

#On Arch, Manjaro, EndeavourOS, etc.
$ sudo pacman -S pdftk

Add Password to PDF File Using PDFtk

To add a password to your PDF file, you can use the following command: Where β€œInput_File. pdf” is the file without a password, and β€œOutput_File.pdf” will be the protected PDF file with a password assigned to the β€œuser_pass” option (in our case, it’s β€œmypasswordβ€œ).

$ pdftk Input_File.pdf output Output_File.pdf user_pw mypassword

Output:

adding password to pdf file with pdftk

Remove Password from PDF File Using PDFtk

To remove a password from a PDF file, you can use the following command: Where β€œInput_File.pdf” is a password-protected PDF, enter the password for the specified PDF file into the β€œinput_pw” option (in our case, β€œmypasswordβ€œ), and finally, enter the output PDF file name (in our case, β€œOutput_File.pdfβ€œ).

$ pdftk Input_File.pdf input_pw mypassword output Output_File.pdf

Output:

removing password to pdf file with pdftk

Method 2: Add and Remove Passwords Using QPDF

QPDF is a free and open-source command-line tool and a C++ library that anyone can use to perform command-line or programmatic manipulation of PDF files. It can perform tasks such as splitting and merging files, creating PDF files from referenced content, encrypting and decrypting files, and more.

To install, open your terminal and execute one of the following commands based on your Linux distribution:

#On Debian, Ubuntu, Mint, Pop!_OS, etc.
$ sudo apt install qpdf

#On RedHat, Fedora, AlmaLinux, CentOS, etc.
$ sudo dnf install qpdf

#On Arch, Manjaro, EndeavourOS, etc.
$ sudo pacman -S qpdf

Add Password to PDF File Using QPDF

To add a password to an unencrypted PDF file, you can use the β€œ--encrypt” option to specify the desired password for locking the input PDF file (in our case, β€œInput_File.pdfβ€œ) and generating the output file (in our case, β€œOutput_File.pdfβ€œ) as an encrypted PDF file.

$ qpdf --encrypt mypassword ownerpass 256 -- Input_File.pdf Output_File.pdf

Output:

adding password to pdf file with qpdf

Remove Password from PDF File Using QPDF

To remove a password from an encrypted PDF file, you can use the β€œ-password” option to specify the password for the encrypted PDF file (in our case, β€œInput_File.pdfβ€œ) and save the output file (in our case, β€œOutput_File.pdfβ€œ) as an unencrypted PDF file.

$ qpdf -password=mypassword -decrypt Input_File.pdf Output_File.pdf

Output:

removing password to pdf file with qpdf

Bonus Tip! Remove Password From a PDF File Using File Manager

On Linux, Windows, and macOS, the option to view a PDF file by simply double-clicking on it is available. Thus, upon opening the PDF file, you can press β€œCtrl+P” to access the Print Window, select the output file name and format, and then click on the β€œPrint” button to save the encrypted PDF file without password protection.

saving PDF file without password using GUI

Final Word

There are many more ways to encrypt and decrypt PDF files, but the ones mentioned above are recommended. Personally, when an encrypted PDF file needs to be decrypted, I prefer the GUI method; otherwise, PDFtk is my go-to option.

Although I want to know what you prefer to use or if you have any other tools in your hand, do let me know in the comment section.

Till then, peace!

Join The Conversation

Users are always welcome to leave comments about the articles, whether they are questions, comments, constructive criticism, old information, or notices of typos. Please keep in mind that all comments are moderated according to our comment policy.