You can protect PDF files with a password by using one simple command.

All you need is install pdftk, a command-line tool for manipulating PDFs. Once installed, run:

pdftk <input file> output <output file> [encryption type] user_pw PROMPT

# An example:
# pdftk test.pdf output test_pw.pdf user_pw PROMPT
  • A prompt will appear, type the password and press Enter.

There are three encryption types: encrypt_40bit, encrypt_128bit and encrypt_aes128 (the default and recommended). You can substitute PROMPT with the password if you prefer (but this is less secure because the command is saved in the shell command history).

If you want to remove the encryption, run:

pdftk <input file> input_pw PROMPT output <output file>
  • A prompt will appear, type the password and press Enter.
Test with this online terminal:

If you have any suggestion, feel free to contact me via social media or email.