How to Set an SSH logon Email notification on Linux
Enabling the SSH service on a virtual private server (VPS) Exposes the server to the Internet, providing an opportunity for hacker attacks, especially when the VPS allows direct access by root. VPS should configure an automatic email warning for every successful SSH login attempt. The owner of the VPS server will receive various SSH server access logs, such as the logon user, Logon Time, and source IP address. This is an important security concern for the server owner to protect the server from unknown login attempts. This is because if hackers use SSH to log on to your VPS through brute force cracking, the consequences will be very serious. In this article, I will explain how to set an email warning for all SSH user logon on CentOS 6, CentOS 7, RHEL 6, and RHEL 7.
Log on to your server as the root user;
Configure a warning (/etc/bashrc) in the global source definition to take effect for both the root user and common user:
[root@vps ~]# vi /etc/bashrc
Add the following content to the end of the above file.
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 selectively enable the warning to only take effect for the root user:
[root@vps ~]# vi .bashrc
Add the following content to the end of/root/. bashrc:
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
Sample configuration file:
# .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 selectively enable the warning to take effect only for specific common users (such as skytech ):
[root@vps ~]# vi /home/skytech/.bashrc
Add the following content to the end of the/home/skytech/. bashrc file:
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
How to Improve the SSH login authentication speed of Ubuntu
Enable the SSH service to allow Android phones to remotely access Ubuntu 14.04
How to add dual authentication for SSH in Linux
Configure the SFTP environment for non-SSH users in Linux
Configure and manage the SSH service on Linux
Basic SSH tutorial
SSH password-free logon details
This article permanently updates the link address: