1

I found the following command:

history | tail -20 | mail -s "log `hostname` pada `date`" mailid[at]corporate.com

I want to combine it with an automatic logout script: The system should send an email alert when the root user has logged out from SSH/terminal. The mail should have the date and include the output of the aforementioned command.

3
  • You do realize that users can just wipe or edit their history before logging out?
    – Daniel Beck
    Aug 15, 2013 at 9:17
  • To do user monitoring right, you could use e.g. sudosh and give nobody the root password -- only allow sudo sudosh. Make sure to contact your legal department before you do this though.
    – Daniel Beck
    Aug 15, 2013 at 9:19
  • yes, i do because my server not use sudo. so why i must log this when user root logout the system must send alert with history, what the command to do that? Aug 15, 2013 at 11:32

1 Answer 1

2

Bash executes at logout the script .bash_logout in the user home dir and /etc/bash.bash_logout (which is run for all users). Basically you could put the command you have in /root/bash_logout and have it execute whenever a login shell for user root exits.

However, it will only work when bash is the shell being used and as long as nobody using root account is not removing those commands from the file, so security-wise this is not really useful (if that is what you had as motivation for this) [Upd: as others already commented].

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .