Related Question, less specific: Automatic cleanup of Bash history
This question focuses on a single problem.
Over time, a user will eventually enter a password on the command line by accident, and may even press enter, which will place the password in history. The user probably was expecting a password prompt, but something was typed wrong, causing that prompt to not show.
This user may not know how to clean up the history with history
and history -d
, or may be too busy to think about it.
I suggest removing all history items that are not found in which
, or other white-list. An added benefit is you will not make the same mistake twice on a mis-typed command, not found in which
Do you know of
- a way to tell
bash
to run my cleanup script before, or right after writing history, - an option that includes this particular
which
based cleanup already, or - an alternative way to prevent passwords from being stored in
history
?
which
is very limited, since built-in commands likecd
are not found and there tons of other possibilities for right commands that can not be found/resolved by which.which
(never usewhich
), usetype
. See How to usewhich
on an aliased command? (and more)setopt correct
) but passwords are likely to be too far from any existing command and so will enter the history anyway. Your method would only handle passwords typed as the first thing on a command line anyway.