How to enable the bash history only caching commands that are acutally in path?

2

1

Having a bash history enabled is a security risk, because when you accientally enter your password into the bash the password gets stored in the bash history. To prevent this a good solution would be to configure the bash history not to save commands that were'nt found in $PATH.

So far this is how i setup the history behaviour

# Dont Save duplicated history lines
HISTCONTROL=irgnoredups:erasedups
HISTTIMEFORMAT="%F-%M-%S --> "
HISTIGNORE="su":"su *":"sudo *":"sudo":"his":"his *":"history":"history *":"halt":"reboot":"apt-get *":"apt-cache *":"aptitude *":"dpkg *"

# need a bigger history 
# uncomment these lines
#HISTSIZE=1000000
#HISTFILESIZE=1000000

It there a way to setup the history so it would only store commands that are in path?

l1zard

Posted 2012-12-06T16:10:26.457

Reputation: 933

Answers

0

You could put all the commands in the variable, I suppose.

HISTIGNORE=${HISTIGNORE}:`find ${PATH//:/ } -printf %f: |sed s/:$//`

Ярослав Рахматуллин

Posted 2012-12-06T16:10:26.457

Reputation: 9 076

umm.. that's the opposite of what you want, isn't it? – Ярослав Рахматуллин – 2012-12-06T17:21:53.703

yes it is. but i think this might not be solved that easy. it seems that i need a backgroud process or something looking whether the command is in $PATH or not. but thanks anyway – l1zard – 2012-12-06T17:30:37.957