Get your server issues fixed by our experts for a price starting at just 25 USD/Hour. Click here to register and open a ticket with us now!

Author Topic: SSH notification mail alert in Centos  (Read 22581 times)

0 Members and 1 Guest are viewing this topic.

arunlalpr

  • Newbie
  • *
  • Posts: 14
  • Karma: +0/-0
SSH notification mail alert in Centos
« on: December 18, 2018, 02:43:06 pm »
SSH notification mail alert in Centos

Open the "bash_profile"

vi ~/.bash_profile

And the following content and replace the " youremailaccount@yourdomain.com" with your email account that you wish to recieve email alerts.
============================
# Email admin when user logs in as root
rootalert() {
  echo 'ALERT - Root Shell Login'
  echo
  echo 'Server: '`hostname`
  echo 'Time: '`date`
  echo 'User: '`who | awk '{ print $1 }'`
  echo 'TTY: '`who | awk '{ print $2 }'`
  echo 'Source: '`who | awk '{ print $6 }' | /bin/cut -d '(' -f 2 | /bin/cut -d ')' -f 1`
  echo
  echo
  echo 'This email is an alert automatically created by your server telling you that someone, even if it is you, logged into SSH as the root user.  If you or someone you know and trust logged in as root, disregard this email.  If you or someone you know and trust did not login to the server as root, then you may have a hack attempt in progress on your server.'

}
rootalert | mail -s "Alert: Root Login [`hostname`]" youremailaccount@yourdomain.com
===================================

« Last Edit: December 19, 2018, 04:27:14 pm by arunlalpr »