Delete bash history automatically

Hi developers and users, It is so exciting to have Rocku linux with great stability and performance. As a new user I am worried that if the root user can see deleted bash_history of sudo user (my). Is there any mechanism to do so? I do not want my bash history (I have sudo) be read by the root user or other sudo users. Please inform me if there is something I can do for deleting the bash_history automatically or not keeping the history in the disk at all.

Sounds sketchy lol. But yes, you can entirely disable bash history by adding the following to your .bashrc:

set +o history

If you only want to disable the history file (and not the ephemeral in-memory history), use this instead:

unset HISTFILE
2 Likes

One I know of as an alternative to the above:

export HISTFILE=/dev/null
1 Like

Another option is to set HISTCONTROL to ignoreboth or ignorespace which will not record any line entered if it begins with a space. This is a bit sneakier in that it can lead others spying on you to believe they are successful, but it is useful because it allows you to not pollute your history with redundant cmds etc. See the bash man page or info pages for other options for HISTCONTROL. I do NOT condone hiding of information from others in general; I do condone optimizing space and search efficiency though.

1 Like

I feel it is appropriate to mention that someone with root would be able to modify Bash so that it records your keystrokes whether you’ve disabled the history feature or not. Perhaps you know in your case it is unlikely that they will do so, but you should be aware that in principle you cannot guarantee privacy from users with that kind of access to a machine.

2 Likes

Maybe you could use like a session based history setup - meaning you’ll clear it on logout. You could try using ~/.bash_logout.

#
# ~/.bash_logout
#

# clear session
history -a && history -c

 

When an interactive login shell exits, or a non-interactive login shell executes the exit builtin command, Bash reads and executes commands from the file ~/.bash_logout, if it exists. »»»

1 Like