Page 1 of 1

How to add Login Alert Notification Debian 10/11

Posted: Wed Dec 30, 2020 7:11 pm
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

Debian 10

Code: Select all

apt-get install mailx
Debian 11

Code: Select all

sudo apt install bsd-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 .bash_profile file. This file sets local environment variables to the users and does some login tasks.

Open .bash_profile file with vi or nano editor

Code: Select all

sudo vi .bash_profile
or

Code: Select all

sudo nano .bash_profile
Note: .bash_profile 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.

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 .bash_profile 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/.bash_profile


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

Re: How to add Login Alert Notification Debian 10

Posted: Thu Dec 31, 2020 10:19 pm
by myVesta
Thanks mate :)

Re: How to add Login Alert Notification Debian 10 / Debian 11

Posted: Fri Sep 23, 2022 10:49 pm
by webxtek
Updated

Re: How to add Login Alert Notification Debian 10/11

Posted: Wed Sep 20, 2023 4:05 pm
by T4B
this is work in debian 12 new version of the panel ?