How to add Login Alert Notification Debian 10/11
Posted: Wed Dec 30, 2020 7:11 pm
Hi 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: &
Now we need to install MailX
Debian 10
Debian 11
Now login as root user and go to root’s home directory by typing
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
or
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.
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
Now you get notified when someone or you acess the system, enjoy
Before starting run:
Code: Select all
apt-get update
Code: Select all
apt-get -y upgrade
Debian 10
Code: Select all
apt-get install mailx
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
Open .bash_profile file with vi or nano editor
Code: Select all
sudo vi .bash_profile
Code: Select all
sudo nano .bash_profile
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]
Code: Select all
cd /home/admin/.bash_profile
Now you get notified when someone or you acess the system, enjoy