Keep logs of user after sudo su

After executing “sudo su -” or “su – ” user will get access as root, And Generally Its difficult to track which command is executed by user in log format.

Centos-Logo

This tutorial/Commands help you to keep log/watch on the command which are executed by user.

Follow below steps to keep logs of user:

Step 1:

First we need to create an directory where we save the log.

# mkdir -p /var/log/historylogs

Step 2:

Paste the following content in “.bashrc” file.

# vim /root/.bashrc
export HISTSIZE=10000
export HISTTIMEFORMAT="%F %T "
export HISTFILE=/var/log/historylogs/history-$(who am i | awk '{print $1}';exit)
export PROMPT_COMMAND='history -a'

Step 3:

After coping the content in “.bashrc” file run following command:

# source /root/.bashrc

Now you must have history of commands in this logs.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

The reCAPTCHA verification period has expired. Please reload the page.