Notify When SSH connection success | Drupal 8

Notify When SSH connection success

Submitted by editor on Fri, 12/16/2016 - 13:45

How to notify by email, url, SMS ... When SSH connection success ?

Method 1. Call Url

You can use this method to call a Custom php script, Custom module, Databaselog .... for example.

1. Create a script (here,

#Example 1.
# Configure your Url:
wget $URL > /dev/null 2>&1

#Or Example 2.
# Configure your Url:
NOW=$(date +"%Y-%m-%d:%H:%M:%S");
curl $URL &>/dev/null;


2. Make the script executable
chmod +x

3. Add the script to /etc/pam.d/sshd
session optional seteuid /path/to/

NOTE 1 : This will also call on disconnection

NOTE 2 :
Set "optional" If you want to still log in if the execution fails.
CAUTION : Set "required" Only After you made sure that it works and if your are sure about what you are doing . login won't be possible unless the execution of your hook script is successful.

Method 2. Send e-Mail using mailx

1. Create a script (here, and make it make it executable (chmod +x

# Configure your email address:

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

2. Add the script to /etc/pam.d/sshd
session optional seteuid /path/to/


Add new comment