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 up a SSH reminder to be sent after SSH login on the email server

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

Share

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

In this issue, the editor will bring you about how to set up SSH login on the Linux server to send email reminders. The article is rich in content and analyzes and describes for you from a professional point of view. I hope you can get something after reading this article.

Enabling SSH services on a virtual private server (VPS) exposes the server to the Internet, providing an opportunity for hackers to attack, especially when VPS also allows root direct access. VPS should configure an automatic email warning for each successful SSH login attempt. The owner of the VPS server is notified of various SSH server access logs, such as logon, login time, and source IP address. This is an important security concern for server owners to protect the server from unknown login attempts. This is because if hackers use brute force cracking to log in to your VPS through SSH, there will be serious consequences. In this article, I will explain how to set an email warning for all SSH user logins on CentOS 6, CentOS 7, RHEL 6, and RHEL 7.

Log in to your server using the root user

Configure the warning (/ etc/bashrc) at the global source definition, which will take effect for both root users and ordinary users:

The code is as follows:

[root@vps ~] # vi / etc/bashrc

Add the following to the end of the above file.

The code is as follows:

Echo 'ALERT-Root Shell Access (vps.ehowstuff.com) on:' `date``who` | mail-s "Alert: Root Access from `who` | cut-d' ('-f2 | cut-d')'- f1`" recipient@gmail.com

You can also optionally let the warning take effect only for root users:

The code is as follows:

[root@vps ~] # vi .bashrc

Add the following to the end of / root/.bashrc:

The code is as follows:

Echo 'ALERT-Root Shell Access (vps.ehowstuff.com) on:' `date``who` | mail-s "Alert: Root Access from `who` | cut-d' ('-f2 | cut-d')'- f1`" recipient@gmail.com

Example of the entire profile:

The code is as follows:

# .bashrc

# User specific aliases and functions

Alias rm='rm-i'

Alias cp='cp-i'

Alias mv='mv-i'

# Source global definitions

If [- f / etc/bashrc]; then

. / etc/bashrc

Fi

Echo 'ALERT-Root Shell Access (vps.ehowstuff.com) on:' `date``who` | mail-s "Alert: Root Access from `who` | cut-d' ('-f2 | cut-d')'- f1`" recipient@gmail.com

You can also optionally allow warnings to apply only to specific ordinary users (for example, skytech):

The code is as follows:

[root@vps ~] # vi / home/skytech/.bashrc

Add the following to the end of the / home/skytech/.bashrc file:

The code is as follows:

Echo 'ALERT-Root Shell Access (vps.ehowstuff.com) on:' `date``who` | mail-s "Alert: Root Access from `who` | cut-d' ('-f2 | cut-d')'- f1`" recipient@gmail.com

The above is how to set up SSH login on the Linux server to send email reminders. If you happen to have similar doubts, please refer to the above analysis to understand. If you want to know more about it, you are welcome to follow the industry information channel.

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