PDA

View Full Version : How not to get logged into BASH History



b0nd
06-15-2011, 03:03 PM
What if you wish to execute a command on linux console but do not wish it to be logged and displayed by #history command?


#history -d $((HISTCMD-1)) && type_your_command_here_and_execute
e.g
#history -d $((HISTCMD-1)) && whoami

The command "whoami" would work and wouldn't be visible in #history command

Explained in detail here (http://thoughtsbyclayg.blogspot.com/2008/02/how-to-delete-last-command-from-bash.html)

Hackuin
06-16-2011, 12:35 AM
What if you wish to execute a command on linux console but do not wish it to be logged and displayed by #history command?


#history -d $((HISTCMD-1)) && type_your_command_here_and_execute
e.g
#history -d $((HISTCMD-1)) && whoami

The command "whoami" would work and wouldn't be visible in #history command

Explained in detail here (http://thoughtsbyclayg.blogspot.com/2008/02/how-to-delete-last-command-from-bash.html)

Why soo mambo jumbo when you can use "space"?
Just give a space in front of a command and it is not logged in #history.
Example:
hackuin@server4$ ls [ note there is space between $ and the command ls ]

And check your #history it will not logged there.

abhaythehero
06-16-2011, 01:38 AM
Why soo mambo jumbo when you can use "space"?
Just give a space in front of a command and it is not logged in #history.
Example:
hackuin@server4$ ls [ note there is space between $ and the command ls ]

And check your #history it will not logged there.


But if we do it as root user then it is being logged by space method.

whereas the earlier method is true for all cases .. it is working as root user as well.

Of course if we are root then we can do anything with history .. :o
but just for 1 command sake...one can prefer the earlier method :D

Hackuin
06-16-2011, 03:05 AM
But if we do it as root user then it is being logged by space method.

whereas the earlier method is true for all cases .. it is working as root user as well.

Of course if we are root then we can do anything with history .. :o
but just for 1 command sake...one can prefer the earlier method :D
Actually, you did-not understand why it did not worked with root. Or why/how the b0nd's method worked. Or, why, my shown method worked for user and not for root.

Actually, consider ubuntu [ natty ], it works for both "root" and "users" by default. But, why? because, my bash version have set my "HISTCONTORL" to "ignorespace", I am pretty sure, you are using some other distro.
The reason is simple, check your Environmental variable "HISTCONTROL" I mean " echo $HISTCONTROL" you will not find "ignorespace" in the variable for you when you type that command with root user, where as if you type the same command with normal user you will find "ignorespace" is set in the variable "HISTCONTROL".
Just export it like, run the command "export HISTCONTROL=ignorespace" with for your users, in your case root and check the space method will work for root too.
Or you can just edit the file ".bashrc" of the user/root and find "HISTCONTROL" line and set "HISTCONTROL=ignorespace" and save it. It will work.

*Note: Either way you need to log-out and log-in back to make the effect work.

b0nd
06-16-2011, 09:05 AM
Why soo mambo jumbo when you can use "space"?
Just give a space in front of a command and it is not logged in #history.
Example:
hackuin@server4$ ls [ note there is space between $ and the command ls ]

And check your #history it will not logged there.

The mambo jumbo is quite useful when by mistake a command has been executed and the user wishes to remove it from history.

#history -d $((HISTCMD-2)) && history -d $((HISTCMD-1))
would delete the last logged command from history.

Definitely can be done with following as well:

#history -d offset
to delete just one line

#for i in {[higher-value-of-offset]..[lower-value-of-offset]}; do history -d "$i"; done;
to delete couple of consecutive lines


Probably the heading I mentioned mislead the discussion.

Thanks for the detailed explanation of <space> followed-by-command technique

Rgds

abhaythehero
06-16-2011, 11:59 AM
Actually, you did-not understand why it did not worked with root. Or why/how the b0nd's method worked. Or, why, my shown method worked for user and not for root.



yups I was using backtrack 4 and the HISTCONTROL wasn't set to ignorespace for root user by default.
Thanks for the explanation .. I got it now :)