Synology usage series 12 – Send email alert when someone login to shell


Since the box is not as secure as I would expect, it would be very useful to receive an email alert when someone login to my box via telnet/SSH.

The instruction are from SynologyWiki, you could refer to the original article for details explanation regarding the steps below.

Pre-requisites

1. The box should be bootstrapped.
2. Install and setup nail, please refer to another tutorial about setup nail using gmail smtp.

Instruction

1. Create a script, i.e. /opt/bin/loginalert.sh, remember modify the email subject, body and email address.


#!/bin/sh

#sends an email to say someone just logged in to the CLI

exec 1>/dev/null 2>/dev/null

var_subject="NAS1 - A user has logged in to the CLI"
var_body = "NAS1 - A user has logged in to the CLI"
var_email=whoever@jflksjfie.com

#send the email
echo "$var_body" | /opt/bin/nail -s "$var_subject" $var_email

while ls "/root/dead.letter"
    do
      sleep 60
      rm "/root/dead.letter"
      echo "$var_body" | /opt/bin/nail -s "$var_subject" $var_email
      sleep 60
done

sleep 60
exit

2. chmod 755 /opt/bin/loginalert.sh

3. Edit the /etc/profile file, add the line below to the end of the file


(sh /opt/bin/loginalert.sh) &

The author claimed that user will not aware the email alert during login, however, I still received message when the loginalert.sh is finished.


[1] + Done                       (sh /volume1/opt/bin/loginalert.sh)

That is not important, because the email is already sent 😉





2 thoughts


Leave a Reply

Your email address will not be published. Required fields are marked *