Currently, we use Snoopy to monitor all commands issued by users on some externally accessible servers. We're in the process of updating everything to RHEL8 to ensure supportability and compliance, and discovered that my beloved Snoopy is no longer maintained. So it won't pass the compliance audit and needs to be replaced.
I looked into using auditd to do it, by enabling "pam_tty_audit.so" in system-auth and password-auth. This did the trick, but the output is, well let's just say it's less then desirable. Not to mention basically unreadable.
I tried setting-up /etc/profile to log by adding this...
function log2syslog
{
declare COMMAND
COMMAND=$(fc -ln -0)
logger -p local1.notice -t bash -i -- "${USER}:${COMMAND}"
}
trap log2syslog DEBUG
And adding this to /etc/rsyslog.conf
local1.* -/var/log/cmdline
It works GREAT! But the solution was declined because it can be overridden by users.
I even tried using rootsh as a shell for users and logging that. Logs well, but there's no time/date stamps on it. So not acceptable.
So back to the question at hand. I need a replacement for Snoopy, that logs EVERY command executed, in a readable format with time/stamps, that users cannot override.
Any thoughts?
The audit system is perfectly capable of logging all users' commands without
pam_tty_audit
, which only logs terminal keystrokes. You should set up auditing to do this instead ofpam_tty_audit
. By default on RHEL 8 auditing is already enabled and logs many system events.To configure auditing to log all user commands, edit the file
/etc/audit/rules.d/audit.rules
. First, since you need syscall auditing, comment out the existing line:Now add for auditing 64-bit and 32-bit commands:
Note that here,
auditcmd
is a key with which you can search the audit logs withausearch
. You can change this to anything you like.Kill and restart auditd. Note that it needs to be killed manually by root; the systemd unit will not let you stop or restart it.
Now run a few commands, and then you can use
ausearch
to see them in the audit log.You can see that all of the information about the command is logged, including its arguments, working directory, user/group, SELinux context, and much more. If you just want the command, that's in the EXECVE line. It's also encoded in hex in the PROCTITLE line, which you can feed to a hex decoder.
See also RHEL KB article How to audit all commands run in the system?