Get the App
SLTechnology News&Howtos  ›  Development  › 

How to implement script SSH login mail alarm

Shulou Source: shulou.com Published: 2022-06-03 09:29:02 11月15日 Update

This article focuses on "how to achieve the script SSH login email alarm", interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Next let the editor to take you to learn how to achieve the script SSH login email alarm bar!

Login protection is a very important link, which will be explained in detail in the following way:

Two days ago @ cyy sent me a picture.

Then I thought of USHQ's ssh login app notification feature, and then it would be nice if I deployed this to a server for my own use. At least one more layer of safety.

First of all, I'd like to thank @ Legion for fixing a few mistakes and Geo2IP's JSON conversion. (P.S. This man is a great god of automation operation and maintenance, and now works in a data statistics enterprise in Germany.)

Of course, compared with him, I am a very poor fighter. Everyone must learn more from @ Legion.

Say what needs to be prepared:

Sendmail or Postfix

Php

Bash

CentOS/Debian/Ubuntu

If you do not have components such as php sendmail Postfix in your production environment, please move to:

@ Legion: Linux uses shell script to realize ssh login alarm

Reference file

The first is the alarm script file.

Shell

#! / bin/sh#### File Name: Login-alert.sh# Author: Jason# Email: master#deamwork.com# Created Time: Tue Jul 21 2015 21:23:16 PM CST # # require jq#wget http://stedolan.github.io/jq/download/linux64/jq-O / usr/local/bin/jq#chmod + x / usr/local/bin/jq#if error Please # following one#PATH=/usr/local/nginx/sbin:/usr/local/php/bin:/usr/local/mysql/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin#Geo2IP by Legion (http://www.dwhd.org/)eval `curl-s "http://ip.taobao.com/service/getIpInfo.php?ip=${SSH_CLIENT%% *}" | jq. | | awk-filler: | [] + | "'{if ($3 million / ^ (country | area | region | city | isp) $/) {print $3" = "$7}}'`# html mail contentcat > > mail-no-base64.html / dev/null 2 > & 1 mail.php EOFphp mail.phpyes y | rm mail-no-base64.html mail-base64.html mail.php |

Then there is how to trigger the script:

Shell

The code is as follows:

Echo "screen-fa-d-m-S WL / etc/Login-alert.sh" > > / etc/profile

In this way, a new terminal or a copy terminal will trigger an alarm.

If you are using smtp, please save the following file as smtp-class.php

PHP

Achieve results:

At this point, I believe that "how to achieve the script SSH login email alarm" have a deeper understanding, might as well to the actual operation of it! Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Tags: Login script alarm email file server learning service content method terminal practical deeper important security security factor people code interest Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MariaDB Apple Xiaomi Shulou Tech Info MySQL