Stop your shell history from leaking sensitive passwords
Environment & Shell Customization (Aliases/Functions/.Bashrc)
Stop your shell history from leaking sensitive passwords
🧩 The Challenge
You’ve definitely typed a password directly into a command line when you were in a hurry, only to realize later it’s sitting in cleartext inside your .bash_history file for anyone to find. It’s a massive security headache that I’ve had to scrub more times than I care to admit.
💡 The Fix
You can force bash to ignore commands that start with a space, which keeps your accidental “mysql -pSecretPassword” flubs out of the logs entirely. It’s an easy win that requires zero effort once it’s set.
export HISTCONTROL=ignorespace
⚙️ Why It Works
Setting this variable tells the shell that any line prefixed with a space character should be completely skipped when it writes to the history file. Just remember to type that leading space and you’re good to go.
🚀 Pro-Tip: Combine this with HISTCONTROL=erasedups to keep your history file from becoming a graveyard of the same command repeated fifty times.
Linux Tips & Tricks | © ngelinux.com | 8/1/2026
