How to avoid commands being logged in bash history


Maybe if you are not a hacker it’s not very useful, and if you are a hacker you probably already knew this. But hey, just in case it might be useful, I’ll share it with the world.

Normally every command you write it the Bash command line gets recorded in it’s history.

A simple example showing that this is true

[pieter@laptop ~]$ echo “Hey, I’ll end up in the history”
Hey, I’ll end up in the history
[pieter@laptop ~]$ history
2 echo “Hey, I’ll end up in the history”
3 history
[pieter@laptop ~]$

The echo command is logged in the history, as well as the history command itself.

Now, if you do not want the command you execute to be logged in the history, set the following variable:

$ export HISTIGNORE="&:[ ]*:exit"

From now on every command you executed preceded with a space isn’t being logged to the bash history. Useful in case you need to execute a command that has a password as parameter (I know, not very secure…but still).

[pieter@laptop ~]$ [SPACE]echo “I remain unnoticed, hahahahaha”
I remain unnoticed, hahahahaha
[pieter@laptop ~]$ history
2 echo “Hey, I’ll end up in the history”
3 history


					
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s