Get the App
SLTechnology News&Howtos  ›  Servers  › 

How to set email reminders for SSH logins on Linux

Shulou Source: shulou.com Published: 2022-06-01 07:27:35 09月16日 Update

This article introduces how to set up email alerts for SSH login on Linux. The content is very detailed. Interested friends can refer to it for reference. I hope it can help you.

What does the.bashrc file do?

The.bashrc file is a script that is executed whenever a new terminal session is started interactively.

1)How to enable email alerts for root

Log in as root and add the following one-line script to the root " .bashrc" file to do 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 order to give effect to the order:

[root@localhost ~]# source .bashrc

When this is done, log in as root. You will receive email alerts similar to the following.

Change root@localhost in the code to the mailbox you use to receive mail.

2)How to enable email alerts for specific users

The following script needs to be added to the specified user's.bashrc file:

[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 root@localhost in the code to the mailbox 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 configuration above. However, you need to add the following script to the last line of the/etc/bashrc 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

About how to set up email alerts for SSH login on Linux to share here, I hope the above content can be of some help to everyone, you can learn more knowledge. If you think the article is good, you can share it so that more people can see it.

Tags: Mail user email email login file script content alert line code more identity mailbox help good mission interest command boy Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Apple NVidia MySQL Microsoft Shulou Technology