Stop piping your sensitive secrets into bash command history
Shell Scripting / Bash Tricks
Stop piping your sensitive secrets into bash command history
🧩 The Challenge
You are debugging a connection issue and accidentally paste a database password into your terminal, then realize it is sitting there in plain text in your .bash_history for anyone to see. I have definitely left a trail of API keys in logs before and had to scramble to rotate them.
💡 The Fix
Adding a space before your command is a simple trick to tell the shell to ignore that line when it saves your history. It keeps your terminal cleaner and stops you from accidentally leaking secrets while you are testing things.
(with a leading space) myscript --password=supersecret
⚙️ Why It Works
Bash looks at the HISTCONTROL variable to decide what to save, and the ignorespace or ignoreboth settings specifically skip lines that start with a whitespace character. It is an old school hack that still works perfectly even on modern distros.
🚀 Pro-Tip: Run export HISTCONTROL=ignoreboth in your .bashrc to make sure it sticks globally.
Linux Tips & Tricks | © ngelinux.com | 12/3/2026
