How to Set an SSH logon Email notification on Linux

Source: Internet
Author: User

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.

  1. Log on to your server as the root user;

  2. Configure a warning (/etc/bashrc) in the global source definition to take effect for both the root user and common user:

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

    Add the following content to the end of the above file.

    1. 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
  3. You can also selectively enable the warning to only take effect for the root user:

    1. [root@vps ~]# vi .bashrc

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

    1. 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:

    1. # .bashrc
    2. # User specific aliases and functions
    3. alias rm='rm -i'
    4. alias cp='cp -i'
    5. alias mv='mv -i'
    6. # Source global definitions
    7. if[-f /etc/bashrc ];then
    8. ./etc/bashrc
    9. fi
    10. 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
  4. You can also selectively enable the warning to take effect only for specific common users (such as skytech ):

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

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

    1. 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:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.