Use mail monitoring ssh to log on to the User shell script

Source: Internet
Author: User

Wget http://caspian.dotconf.net/menu/Software/SendEmail/sendEmail-v1.56.tar.gz

Tar xvf sendEmail-v1.56.tar.gz
Music sendEmail-v1.56 sendEmail


Vi/etc/ssh/sshrc
#! /Bin/sh
User = $ USER
Ip =$ {SSH_CLIENT % *}
If ["$ user "! = "Root"] | ["$ ip "! = "192.168.2.88"]
Then

/Home/shell/sendEmail-f XXX @ XXX-t XXX @ XXX-s smtp. XXX-u "view who logged on ### 192.168.2.4 ###"-xu USER-xp PASSWD-m "### time: 'date + % Y-% m-% d '###. ### user: $ USER @ 'hostname '###. ### ClientIP: $ {SSH_CLIENT % *}###"
Fi

Chmod + x/etc/ssh/sshrc

####################

$ USER: Get the username used for system login through ssh

$ {SSH_CLIENT % *} obtains the IP address of the username used to log on to the system through ssh.

If ["$ user "! = "Root"] | ["$ ip "! = "192.168.2.88"] use or to determine the source and whether to send an alarm by email

######################################## ###

Test:

1. Use root and IP address 192.168.2.88 to check whether an alarm is sent by email.


The test result is: no email alert is reported.

2. Use root and IP address 192.168.2.87 to check whether an alarm is triggered.



The test result is: email sending alarm

View Email:


This script is very useful for ssh security monitoring. You can always know the situation when the system logs in illegally, so as to protect server security in a timely manner.

Address: http://youzao.blog.51cto.com/3946111/740707

Related Article

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.