back       next

Eliminate Command Line Histories with chattr (change attribute)...

If you use bash as the default shell, it keeps a history of commands accessed via the `history` command for convenience. This could end up being a security problem if someone were able to compromise a users' home directory. In some cases, this could expose improperly used passwords or special privileges available to the user such as sudo.

Consider disabling this by changing the attribute of the file to lock out the ability to update the file. As root:

# cat /dev/null > ~user/.bash_history
# chattr +i ~user/.bash_history

The user will still have a command line history, but it will only apply to the current session. When the user logs out, the information will not be saved. To have this apply to all future users, make the changes in the "/etc/skel" directory.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

HISTFILE as /dev/null

This will redefine HISTFILE as /dev/null, telling the shell to write it's
history to this file. Therefore, all data passed to null device is thrown away.

export HISTFILE=/dev/null

Auto clear history on logout

Additionally, you can clear out the history by including the below line in the ".bash_logout" file.

export HISTSIZE=0

Post new comment

  • Lines and paragraphs break automatically.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Copy the characters (respecting upper/lower case) from the image.