Enabling the SSH service on the server makes the server exposed to the Internet, providing an opportunity for hacking, especially when the Linux server also allows direct access by root. The linux server should configure an automatic email warning for each successful SSH login attempt.
The owner of the Linux server will get notifications of various SSH server access logs, such as logged in, login time, and source IP address. This is an important security concern for server owners to protect their servers from unknown login attempts. This is because if a hacker uses brute force to log in to your Linux server via SSH, the consequences are serious. In this article, I will explain how to set up an email warning for all SSH user logins on CentOS 6, CentOS 7, RHEL 6, and RHEL 7.
1. For all users who can log in to SSH on Linux server (root and normal users)
Edit vim /etc/bashrc Add
echo 'ALERT - at the end - Root Shell Access (root.aliyun.cnhzz.com) on:' `date` `who` |
Mail -s "Alert: Root Access from `who |
Cut -d'(' -f2 |
Cut -d')' -f1`" [email protected], only valid for root users
Edit vim .bashrc Add
echo 'ALERT - Root Shell Access at the end Root.aliyun.cnhzz.com) on:' `date` `who` |
Mail -s "Alert: Root Access from `who |
Cut -d'(' -f2 |
Cut -d')' -f1`" [email protected], you can also optionally make the warning only valid for specific ordinary users (eg bin2u):
Edit vim /home/bin2u/.bashrc Add
echo 'ALERT - Root Shell Access (root.aliyun.cnhzz.com) on:' `date` `who` at the end |
Mail -s "Alert: Root Access from `who |
Cut -d'(' -f2 |
Cut -d')' -f1`" [email protected] above settings are valid on the spot. After logging out of ssh, you can receive email reminder if you log in again. If you have not received it, please send an email to test;
echo 'ALERT - Root Shell Access (root.aliyun.cnhzz.com) on:' `date` `who` |
Mail -s "Alert: Root Access from `who |
Cut -d'(' -f2 |
Cut -d')' -f1`" [email protected] If you find a similar error message
send-mail: warning: inet_protocols: IPv6 support is disabled: Address family not supported by protocol send-mail : warning: inet_protocols: configuring for IPv4 support only postdrop: warning: inet_protocols: IPv6 support is disabled: Address family not supported by protocol postdrop: warning: inet_protocols: configuring for IPv4 support only View current inet_protocols
# /usr /sbin/postconf |
Grep inet_protocolsinet_protocols = all changed to ipv4
# vi /etc/postfix/main.cfinet_protocols = all changed to inet_protocols = ipv4 send mail directly via external SMTP (discard sendmail and postfix directly)
My friends will definitely be entangled in the e-mail here for a while, and there will be a variety of misunderstandings that will not be resolved for a while. So using external SMTP to send mail is a good way.
#vi /etc/mail.rc set [email protected] smtp=smtp.139.comset smtp-auth-user=123456set smtp-auth-password=sbsbsbsbset smtp-auth=login after login Your accepted email will receive a similar email. Ssh-mail
Reprinted please specify: rookie HOW webmaster » linux how to set up SSH login email email reminder notification
There is no doubt that Red Hat is indeed the choice of many companies considering Linux, but in rece
you want under Linux How to install the jdk you want under Linux? Last time we talked about how to u
Multiple startup files Adding multiple startup files by saying that compilation will be wrong. But t
In different Linux distributions, there will be different GUI programs that can display various syst
CentOS Linux lftp command backup file
Teach you to crack the root password of the Linux system
Forgot your password solution under liunx
Hard disk bad track detection tutorial under Linux
How beginners learn Linux system command operations
Linux operating system partitioning tool Fdisk tool introduction
Linux File Sharing - Process and Open File
IPsec, site-to-sito VPN Simple Experiment
Squid log file is too large, how to deal with it?
Analysis of Linux system computer crash causes
Linux installation of the mail command method to solve the problem of not finding the mail command
Win7 program does not respond to time reduction method
Microsoft stopped Win10 support after four years, and the upgrade cost
Windows7 Tips: Completely uninstall IE8 browser
DNF Assassin's second point contract point and non-contract point point recommendation
How does Win7 use CMD commands to forcibly delete files?
What can I do if the RNDIS driver cannot be installed in the win7 pure version?
XP system does not correctly recognize the built-in modem
Win7 system hard disk icon can not be displayed, how to do
Unable to register flash player's activex solution
Win10/Win7/Win8.1 photo viewer picture background yellow how to solve