β new script: PDF remove password
β’ 384 words β’ 2 min β’ updated
Problem statement: Given a password-protected .pdf file, remove its
password. It’s indifferent whether the file gets overwritten or whether a new
one is created.
ghostscript can do it:
gs -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=output.pdf -c .setpdfwrite -f input.pdfqpdf can do it:
qpdf --decrypt --password="{my pass}" input.pdf output.pdfI am not expected to memorize these CLI flags.
I do not want to look them up every time either.
There are various approaches to tackle this:
- a shell alias (
alias foo=) - a shell function
foo() {} - a shell script (
*.sh) - a comma script
- a copyable snippet (e.g. stored in Obsidian / LogSeq or some other digital garden / personal wiki / second brain app)
- a snippet (e.g. in RayCast or Espanso)
- ask the AI each time
googlesearch for it each time
Lately I’ve been favouring the shell script approach, so here we go with pdf_password_remove.sh:
Usage #
Remove password protection from PDF files.
# Interactive password prompt (most secure)
pdf_password_remove secret.pdf
# Process multiple files
pdf_password_remove report.pdf invoice.pdf contract.pdf
# Provide password via command line
pdf_password_remove --password=BANANA42SPLIT secret.pdf
# Custom output filename (single file only)
pdf_password_remove -o unlocked.pdf secret.pdfExample Output #
% pdf_password_remove --password=PIZZA69SLICE financial-report.pdf tax-form.pdf
β Successfully processed: financial-report.pdf β financial-report-unlocked.pdf
β Successfully processed: tax-form.pdf β tax-form-unlocked.pdf
Summary: Successfully processed 2/2 file(s)Features #
- Process single or multiple PDF files in one command
- Secure interactive password prompt (hidden input)
- Command-line password option for automation/scripts
- Default output naming: adds
-unlockedsuffix - Custom output filename with
-oflag (single file only) - Clear success/failure indicators for each file
- Validates PDF files before processing
Prerequisites #
Requires either ghostscript (preferred) or qpdf to be installed:
# macOS
brew install ghostscript # Preferred
brew install qpdf # Alternative
# Linux
sudo apt install ghostscript # Preferred - Debian/Ubuntu
sudo apt install qpdf # Alternative
sudo dnf install ghostscript # Preferred - Fedora
sudo dnf install qpdf # Alternative
sudo pacman -S ghostscript # Preferred - Arch
sudo pacman -S qpdf # AlternativeThe script automatically detects and uses whichever tool is available, preferring ghostscript if both are installed.
Security Note #
Using --password on the command line will expose the password in shell history
and process lists. For sensitive documents, use the interactive prompt instead
(default behavior when password is not provided).