How to add Login Alert Notification Debian 10

Post Reply
User avatar
Posts: 27
Joined: Wed Nov 18, 2020 7:43 pm
How to add Login Alert Notification Debian 10

Post by webxtek »

Hi :D Today will be leaving here how you can setup your system to notify when someone logs in on your server or panel, you can setup for root, admin, or any user.

Before starting run:

Code: Select all

apt-get update

Code: Select all

apt-get -y upgrade
Now we need to install MailX

Code: Select all

apt-get install mailx
Now login as root user and go to root’s home directory by typing

Code: Select all

cd /root
Next, add an entry to the .bashrc file. This file sets local environment variables to the users and does some login tasks.

Open .bashrc file with vi or nano editor

Code: Select all

sudo vi .bashrc

Code: Select all

sudo nano .bashrc
Note: .bashrc is a hidden file, it won't be seen by doing ls -l command. To find Hidden file you use the ls -a flag to see hidden files in Linux.

Add the following whole line at the bottom of the file.

Make sure to replace “ServerName” with a hostname of your Server and change “[email protected]” with a your email address.

Code: Select all

echo 'ALERT - Root Shell Access (ServerName) on:' `date` `who` | mail -s "Alert: Root Access from `who | cut -d'(' -f2 | cut -d')' -f1`" [email protected]
Now you can log out and log in to test the email notification, that will notify you when you login as ROOT, in case you want to add this setting to any other user, you just need to edit the .bashrc of that user and add the code on the end. Lets say you want to login as admin and get notified, you need to edit

Code: Select all

cd /home/admin/.bashrc

Now you get notified when someone or you acess the system, enjoy :D

User avatar
Site Admin
Posts: 551
Joined: Fri Jun 19, 2020 9:59 am
Your location: Serbia, Niš and Belgrade
First name and last name: Predrag Damnjanović
Re: How to add Login Alert Notification Debian 10

Post by dpeca »

Thanks mate :)

Post Reply