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.


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


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


#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"

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

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

sleep 60

2. chmod 755 /opt/bin/

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

(sh /opt/bin/ &

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

[1] + Done                       (sh /volume1/opt/bin/

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 *