Skip to content

blog.anichin.com

A place where you can find a little of everything.

Archives

Categories

Tags

  • .Net (5)
  • AI (21)
  • asp.net core (5)
  • Azure (26)
  • Azure DevOps (4)
  • Backup (4)
  • CenturyLink (4)
  • Cooking (13)
  • dd-wrt (9)
  • docker (28)
  • Entware (5)
  • Fire TV (6)
  • freenas (15)
  • Git (9)
  • Greece (6)
  • Hyper-V (4)
  • IoT (4)
  • job search (4)
  • Kubernetes (7)
  • linux (7)
  • networking (5)
  • Nextcloud (4)
  • OpenVPN (7)
  • Oracle Cloud (6)
  • pfSense (14)
  • Pi-hole (4)
  • Plex (10)
  • Portainer (6)
  • Prometheus (4)
  • Proxmox (9)
  • Raspberry Pi (5)
  • RDP (5)
  • site-to-site VPN (7)
  • sitecore (18)
  • SQL Server (6)
  • SSH (8)
  • SSL (4)
  • Synology (16)
  • Travel (6)
  • Ubuntu (24)
  • vpn (12)
  • Windows 11 (4)
  • wireguard (6)
  • WordPress (4)
  • Youtube (6)

Author: Angel

Литературен свят

Електронно списание Литературен Свят

Posted on February 27, 2019February 27, 2019Categories UncategorizedLeave a comment on Литературен свят

Dan Wahlin – Pluralsight courses

https://app.pluralsight.com/profile/author/dan-wahlin

Posted on February 26, 2019February 26, 2019Categories LearningTags PLuralsight coursesLeave a comment on Dan Wahlin – Pluralsight courses

Build Your First CI/CD Pipeline using Azure DevOps

https://mikepfeiffer.io/azure-devops-pipeline.html

Posted on February 24, 2019February 24, 2019Categories AzureTags Azure, Azure CI/CDLeave a comment on Build Your First CI/CD Pipeline using Azure DevOps

How To Replace Front Inside Door Handle 03-12 Volvo XC90

Posted on February 12, 2019February 12, 2019Categories Car maintenance, Volvo XC90Tags Front Inside Door Handle, Volvo XC90Leave a comment on How To Replace Front Inside Door Handle 03-12 Volvo XC90

How do I set up an email alert when a ssh login is successful?

Original: https://askubuntu.com/questions/179889/how-do-i-set-up-an-email-alert-when-a-ssh-login-is-successful

Since the sshrc method doesn’t work if the user has their own ~/.ssh/rc file, I’ll explain how to do this with pam_exec as @adosaiguas suggested. The good thing is that this can also be easily adapted to login types other than ssh (such as local logins or even all logins) by hooking into a different file in /etc/pam.d/.

First you need to be able to send mail from the command line. There are other questions about this. On a mail server it’s probably easiest to install mailx (which is probably already installed anyway).

Then you need an executable script file login-notify.sh (I put it in /etc/ssh/ for example) with the following content. You can change the variables to change the subject and content of the e-mail notification. Don’t forget to execute chmod +x login-notify.sh to make it executable.

#!/bin/sh

# Change these two lines:
sender="sender-address@example.com"
recepient="notify-address@example.org"

if [ "$PAM_TYPE" != "close_session" ]; then
    host="`hostname`"
    subject="SSH Login: $PAM_USER from $PAM_RHOST on $host"
    # Message to send, e.g. the current environment variables.
    message="`env`"
    echo "$message" | mailx -r "$sender" -s "$subject" "$recepient"
fi

Once you have that, you can add the following line to /etc/pam.d/sshd:

session optional pam_exec.so seteuid /path/to/login-notify.sh

For testing purposes, the module is included as optional, so that you can still log in if the execution fails. After you made sure that it works, you can change optional to required. Then login won’t be possible unless the execution of your hook script is successful (if that is what you want).

For those of you in need of an explanation of what PAM is and how it works, here is a very good one.

Just make sure you have UsePAM set to yes in your sshd_config

And this is how to use Pushover API for alerts instead of email:

#!/bin/sh

# This script monitors /var/log/auth.log for SSH logins
# and sends a notification via Pushover when one is
# detected.

# Need to wait a bit before actually starting this script
sleep 90 # sleeps for 90 seconds

# Pushover
PUSHOVER_TITLE="FreeNAS SSH Login" # This is the title for each message.
APITOKEN=******
USERKEY=******

# Log
LOG=/mnt/Tank/sshNotify.log
/bin/date > $LOG
echo "PID: $$" >> $LOG

# Priority:   -2 to generate no notification/alert
#             -1 to always send as a quiet notification
#              0 to use the default priority
#              1 to display as high-priority and bypass the user's quiet hours
#              2 to also require confirmation from the user.
#                Note: For priority 2, the retry and expire parameters
#                      must also be supplied.

# Monitoring loop

echo "Script running." >> $LOG
/usr/bin/tail -Fn0 /var/log/auth.log | \
while read line ; do
    echo "$line" | grep -q " Accepted publickey for "
    if [ $? = 0 ] ; then
        TS=$(date +%s)
        USER=$(echo "$line" | cut -d':' -f4 | cut -d' ' -f5)
        IP=$(echo "$line" | cut -d':' -f4 | cut -d' ' -f7)
        /usr/local/bin/curl https://api.pushover.net/1/messages.json -d "token=${APITOKEN}&user=${USERKEY}&title=${PUSHOVER_TITLE}&message=User: ${USER}   IP: ${IP}&timestamp=${TS}&priority=-1"
    fi
done

echo "Script finished, will now exit." >> $LOG
/bin/date >> $LOG
exit 0

If using this with FreeNAS run the script by creating an entry under Tasks –> Init/Shutdown Scripts. The fields are:

Type: Command
Command: /bin/sh /mnt/Tank/sshNotify.sh &
When: postinit
Posted on January 28, 2019January 29, 2019Categories Howto, UbuntuTags Send email on login, SSHLeave a comment on How do I set up an email alert when a ssh login is successful?

Use Fail2ban to Secure Your Server

https://www.linode.com/docs/security/using-fail2ban-for-security/

How to install Fail2ban on FreeBSD
Posted on January 28, 2019January 28, 2019Categories FreeNAS, HowtoTags Fail2BanLeave a comment on Use Fail2ban to Secure Your Server

Tutorial: Using Azure DevOps to setup a CI/CD pipeline and deploy to Kubernetes

https://cloudblogs.microsoft.com/opensource/2018/11/27/tutorial-azure-devops-setup-cicd-pipeline-kubernetes-docker-helm/

Posted on January 26, 2019January 26, 2019Categories UncategorizedLeave a comment on Tutorial: Using Azure DevOps to setup a CI/CD pipeline and deploy to Kubernetes

LFCE: Advanced Linux Networking

https://app.pluralsight.com/library/courses/linux-networking-advanced-lfce/table-of-contents
Posted on January 23, 2019January 23, 2019Categories Howto, InternetTags LInux NetworkingLeave a comment on LFCE: Advanced Linux Networking

MASTERING AZURE WITH CLOUD SHELL

https://www.thomasmaurer.ch/2019/01/azure-cloud-shell

Posted on January 23, 2019January 23, 2019Categories AzureTags Azure, Azure Cloud ShellLeave a comment on MASTERING AZURE WITH CLOUD SHELL

Bootstrap Kubernetes the hard way on Microsoft Azure Platform

https://github.com/ivanfioravanti/kubernetes-the-hard-way-on-azure

Posted on January 22, 2019January 22, 2019Categories AzureTags Azure, KubernetesLeave a comment on Bootstrap Kubernetes the hard way on Microsoft Azure Platform

Posts pagination

Previous page Page 1 … Page 45 Page 46 Page 47 … Page 65 Next page
Proudly powered by WordPress