Guide | This article describes how to set up email reminders for ssh login on Linux systems . To receive alerts about unauthorized or illegal login access to the root user. |
What does the .bashrc file do?
.bashrc
File is a script , every time when you start a new terminal session in interactive mode, it will execute the script .
1) How to enable email alerts for root users
Log in as the root user, and then add the following line of script to the root user ".bashrc" file to achieve this:
[root@localhost ~]# vim /root/.bashrc
echo 'ALERT - SSH root shell access found on '$HOSTNAME' on:' `date` `who` | mail -s "Alert: SSH root shell access" root@localhost
Execute the following command to make the command effective:
[root@localhost ~]# source .bashrc
When finished, log in as the root user. You will receive an email alert similar to the following.
Change the code in the code root@localhost
to the mailbox that you use to receive mail.
2) How to enable email alerts for specific users
The following script needs to be added to the .bashrc
file of the specified user :
[root@localhost ~]# vim /home/bob/.bashrc
echo 'ALERT - '$USER' shell access found on '$HOSTNAME' on:' `date` `who` | mail -s "Alert: User shell access" root@localhost
Change the code in the code root@localhost
to the mailbox that you use to receive mail.
The prompt after login is as follows:
3) How to enable email alerts for all users
Enabling email alerts for all users is similar to the above configuration. But you need to add the following script to the /etc/bashrc
last line of the file:
[root@localhost ~]# vim /etc/bashrc
echo 'ALERT - '$USER' shell access found on '$HOSTNAME' on:' `date` `who` | mail -s "Alert: User shell access" root@localhost
to sum up
This article describes how to set up email reminders for ssh login on Linux systems. To receive alerts about unauthorized or illegal login access to the root user. Linux should be learned like this