Enable date-stamp in your .bash_history file and be more secure

by Phil Dufault on September 4, 2008 · 1 comment

in Featured,Linux,Shell

While your .bash_history file can be easily cleared by a malicious person that’s gained access to your account,  we can make it harder for them to achieve this.

Note: this works in bash v3 and up, so you should be pretty safe in today’s world of bash v3.3+ everywhere.

If you’d like to add the timestamping to all users on the machine, this is how we can do it.

The first file to edit is/etc/profile so this applies to all users to timestamp their logs.  If you’re looking to keep this restricted to a single user, you can just add it to their .bashrc in their  home directory (~username).

Here’s what you need to add:

HISTTIMEFORMAT="%D %T "

To get your current session to use the new settings:

source /etc/profile

Check it out your last 20 commands, datestamped:

history | tail -n20

I really do like BASH, and it’s really very powerful underneath it’s simple exterior.

{ 1 comment… read it below or add one }

Andrew Johnson November 18, 2008 at 11:10 pm

Excellent tip, think I’ll use it. Thanks =)

Leave a Comment

Previous post:

Next post: