Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to set email reminders for SSH logins on Linux

2025-04-05 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

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.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report