If you read this far, tweet to the author to show them you care. Tweet a thanks
Ravi Saive
I am an experienced GNU/Linux expert and a full-stack software developer with over a decade in the field of Linux and Open Source technologies

Each tutorial at TecMint is created by a team of experienced Linux system administrators so that it meets our high-quality standards.

Join the TecMint Weekly Newsletter (More Than 156,129 Linux Enthusiasts Have Subscribed)
Was this article helpful? Please add a comment or buy me a coffee to show your appreciation.

35 thoughts on “How to Get Root and User SSH Login Email Alerts”

  1. Create a alert on my server such that if anyone other than my and my manager IP’s login to the server we should get an mail based alert with the user ID & ip address.

    Please help.

    Reply
  2. Hi, I just tested this on my Linux box and it works well. However, if i need to reverse the script, how do i achieve that?

    echo ‘ALERT – Root Shell Access (ServerName) on:’ `date` `who` | mail -s “Alert: Root Access from `who | cut -d'(‘ -f2 | cut -d’)’ -f1`” [email protected]

    Reply
  3. Hello!

    I get this when attempting to install mailx the above command.

    Reading package lists ... Done
    Building the dependency tree
    Reading status information ... Done
    The mailx package is a virtual package provided by:
      mailutils 1: 3.1.1-1
      bsd-mailx 8.1.2-0.20160123cvs-4
    You must explicitly select a package to install.
    
    E: The "mailx" package does not have a version that can be installed
    

    As the message says, apt-get install mailutils works.

    Thank you for sharing your knowledge.

    Reply
  4. When i am trying the command i am getting.

    line 13: unexpected EOF while looking for matching `''
    line 14: syntax error: unexpected end of file
    

    i didn’t find any solutions

    Reply

Leave a Reply to vikash khanna Cancel reply

Have a question or suggestion? Please leave a comment to start the discussion. Please keep in mind that all comments are moderated and your email address will NOT be published.