Send An Email When Someone Logs In

By | November 13, 2011

You can send out an "alert" email when someone logs in to your server (or workstation) by taking two steps*.

Now if you prefer to send the alert to your smart phone instead of your inbox, you can easily apply what wikipedia has to say regarding text-to-sms gateway addresses after you finish reading this post.

Step 1) is done by placing this script into a file named "iloggedin" the /usr/local/sbin/ directory, and making it executable with chmod +x /usr/local/sbin/iloggedin. While you are creating the file, make sure to modify the RECIPIENT declaration on line 2 so that it points to the email address at which you want to receive alerts. Once you do this, you’re half way done…

Step 2) is to modify your /etc/profile file. Add the following line to the bottom of the file:

/usr/local/sbin/iloggedin >/dev/null 2>&1 & disown -a

*You will need to have a working email setup before you can send mail from your Linux operating system.

This concludes our little howto.