I’ve had to run and maintain numerous servers over the years and one thing you always want to know about is when someone actually logs in as root, and I’m sure it may help you too.
The following simple commands below can be setup for you’re VPS or Dedicated server and will trigger an email notification once someone logs in, This can be useful for teams, dedicated appliances or just as notification of other service events and can be replicated to work under other user accounts too!
it’s achieved very simply by using the .bashrc file to send the email upon a login,
Firstly in let’s login to the server via SSH or as the console,
- cd /root
- nano (or pico) .bashrc
- append the following to the end of the file:
- echo ‘Root Shell Access on:’ `date` `who` | mail -s “Alert: Root Access from `who | cut -d”(” -f2 | cut -d”)” -f1`” email@example.com
- Save and Exit (Ctrl + X, Y)
That’s it, now once you log out and back in – an email should be sent to you,