How to set up email reminders for SSH login on Linux

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?

.bashrcFile 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

How to set up email reminders for SSH login on Linux How to set up email reminders for SSH login on Linux
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.
How to set up email reminders for SSH login on Linux How to set up email reminders for SSH login on Linux
Change the code in the code root@localhostto 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 .bashrcfile 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

How to set up email reminders for SSH login on Linux How to set up email reminders for SSH login on Linux
Change the code in the code root@localhostto the mailbox that you use to receive mail.

The prompt after login is as follows:
How to set up email reminders for SSH login on Linux How to set up email reminders for SSH login on Linux

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/bashrclast 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

How to set up email reminders for SSH login on Linux How to set up email reminders for SSH login on Linux

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

Guess you like

Origin blog.csdn.net/Linuxprobe18/article/details/114252493
Recommended