How to add Login Alert Notification Debian 10/11

Post Reply
User avatar
webxtek
Posts: 51
Joined: Wed Nov 18, 2020 7:43 pm

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
Last edited by webxtek on Wed Sep 28, 2022 1:10 pm, edited 4 times in total.
User avatar
myVesta
Site Admin
Posts: 928
Joined: Fri Jun 19, 2020 9:59 am
Has thanked: 8 times
Been thanked: 6 times

Thanks mate :)
User avatar
webxtek
Posts: 51
Joined: Wed Nov 18, 2020 7:43 pm

Updated
User avatar
T4B
Posts: 160
Joined: Sat Jul 11, 2020 9:44 am
Been thanked: 5 times

this is work in debian 12 new version of the panel ?
Post Reply