How to enable command line audit logging in linux
This article will show the procedure to log all commands into the shell in a linux environment to log file. This can be useful for auditing user actions or for security audits.
Solution
Login to the linux box and assume root
#sudo su -
Edit /etc/profile and add the following lines to the bottom of the file:
# command line audit logging function log2syslog { declare COMMAND COMMAND=$(fc -ln -0) logger -p local1.notice -t bash -i -- "${USER}:${COMMAND}" } trap log2syslog DEBUG
- Save and exit /etc/profile
Edit /etc/rsyslog.conf and add the following lines to the bottom of the file:
# command line audit logging local1.* -/var/log/auditlogging
- Save and exit /etc/rsyslog.conf
Either restart the rsyslog service, or restart the whole machine to release all user sessions - forcing a reload of the bash profile and enacting the changes
#systemctl restart rsyslog
The audit logging will be visible under /var/log/auditlogging and will look like this:
cmdline audit logs |
Nicely explained with step by step commands. Thanks for the blog.
ReplyDeleteWell explained with step by step commands. Thank You Manas
ReplyDelete