Linux: Sending email in case of Root login
A small article to make sure that Linux sends an email in case of login on root.
Very simple for that we edit the bashrc of the account for which we want to send an email in case of login. The ~ / .bashrc file is read by bash when it is launched in interactive mode (when accessing the terminal in ssh for example).
- For root this goes under /root/.bashrc
- For other users it is under their home / home /
- For all system users we will edit /etc/bash.bashrc
We place the following line at the end of the file (replace the email address at the end)
1
|
echo ‘ALERT – Root Shell Access (ServerName) on:’ `date` `who` | mail –s « Alert: Root Access from `who | cut -d'(‘ -f2 | cut -d’)’ -f1` » your@yourdomain.com
|
To test, you must log out and then log in to the account again so that the bashrc.