Skip to content

Admin's Cave

The place of IT & Fun !
Menu
  • Home
  • Learn Python the Hard Way
  • Command line course
  • Contact
  • Privacy Policy
12/08/2016
HomeE-LearningManaging Linux Servers ? Recieve An Email When Someone Logs Into your Server!

Managing Linux Servers ? Recieve An Email When Someone Logs Into your Server!

By adminus E-Learning, Geek Tech  0 Comments

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

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…

 

#!/bin/bash
RECIPIENT=”your.email@address.here”;
PREFIX=”LOGIN ALERT!”;
REMOTEIP=$(/bin/echo $SSH_CLIENT | /usr/bin/awk ‘{ print $1 }’);
TIME=$(/bin/date +’%r, %D’);
HOST=$(/bin/hostname -f);

if [[ “$REMOTEIP” == “” ]]; then
REMOTEIP=’localhost’;
fi

/bin/cat < Remote user $USER just logged in to $HOST at $TIME from $REMOTEIP
LOGGEDIN

exit $?

 

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.

from : http://www.atrixnet.com/send-an-email-when-someone-logs-in/

Tags:alert, linux, login, script

Related Posts

Windows 10 is Out Today: Should You Upgrade?

Windows 10 is Out Today: Should You Upgrade?

7 System Monitoring Tools for Linux to Keep an Eye on Vital System Stats

Calculate IP Subnet Address with ipcalc Tool

About Author

adminus

Linux Windows & Networks System Administrator with some years of professional working experiance in the IT field. This is my personal blog where I make some notes and memo's on interesting materials.

Search articles

Categories

  • CISSP
  • Downloads
  • E-Learning
  • Ebay Scammers
  • Fun
  • Geek Tech
  • Geen categorie
  • Howtoforge
  • howtogeek
  • IT-Software
  • Media
  • Tecmint
  • Uncategorized
  • Unixmen

Recently

  • Ebay scammer be advised ! user : wiskha-4842, Wissam Khalaf
  • Prepare for CISSP 2022 exam for free.
  • 10 lsof Command Examples in Linux
  • Linux Performance Monitoring with Vmstat and Iostat Commands
  • 13 Linux Network Configuration and Troubleshooting Commands
Admin's Cave Copyright © 2023.
Theme by MyThemeShop. Back to Top ↑