How to Get Linux Server Sends Email Alert on Root Login

To improve the security of the server, especially web server which exposes to the Internet and possible worldwide hackers, it’s best to enable server to automatically send a notification email to predefined email address everytime someone logs in as root to the host. To configure the automatic email alert notification to a default email address on each incident of root log on on the server, use the following guide.

  1. Login to the server via SSH using as root ID.
  2. Ensure that you’re at home directory of root. The open up the .bash_profile for editing using pico or vi by typing one of the following commands at command shell line:

    pico .bash_profile
    vi .bash_profile

  3. Scroll down to the end of the file and add the following line:


    echo 'ALERT - Root Shell Access on:' `date` `who` | mail -s "Alert: Root Access from `who | cut -d"(" -f2 | cut -d")" -f1`" user@example.com

    Replace user@email.com with the actual email account address that you want to the root access alert notification been sent to. Note that you can change the text contains in the email alert too. The text starting with first ALERT is written as email body, and you can add in other info such as host name or change the wordings. The second Alert is the email title which you can change to your own too.

Now logout and login again as root, you should receive an email alert at your inbox. The security trick should works on most popular flavor of Linux such as RedHat, CentOS, Ubuntu, FreeBSD and etc.

Share and contribute or get technical support and help at My Digital Life Forums.



2 Responses to “How to Get Linux Server Sends Email Alert on Root Login”

  1. Linux - wysyłanie maila o logowaniu na konto roota « Barni.LOG
    August 12th, 2007 03:10
    1

    [...] Linux - wysyłanie maila o logowaniu na konto roota Bardzo użyteczny skrypcik [...]

  2. Jon
    May 3rd, 2008 05:43
    2

    ‘who -m’ makes the output much cleaner when using this on a system that has multiple users logged on…

    -m reports only hostname and user associated with stdin terminal

Leave a Reply

You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Subscribe without commenting


Custom Search

New Articles

Incoming Search Terms for the Article

linux turn off mail notification - linux email alerts - linux change root email - linux mail root - linux change root email address - linux root mail - mail alerts in linux - change root email - email when root logs on - turn off mail notification linux - linux root email address - email alerts linux - linux server email security notifications - linux mail change from address - email alert when linux server is login - Change root mail - linux send email login - linux root login alert - email for root - linux send email on ssh login - linux notify on login - linux login notification - linux email root logs - linux mail from address - linux system send alerts rss -news - server email notifications - linux server status mail - linux root email as different user - ssh alert linux - where do we find mail for root + linux - mail logins linux - mail root linux - redhat linux directory file access email alert notification - all - linux root alert - linux some one is sending mail from my server who - server to email logs linux - ubuntu mail command line server change root email address - Linux ubuntu ids alerte sms - any change in linux +email notification - change user from addresses linux - disable email notifications on linux server - how to set root email ID - linux email on logins - how to get the alert from mails from linux server - linux default email address change - Linux: root email - linux email alert failure - linux mail alert - root email account linux -