Created
July 11, 2021 07:19
-
-
Save kokoye2007/cc302f4e519f8e84694448a9aca48947 to your computer and use it in GitHub Desktop.
SSH - User Login Logout
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/sh | |
# ForceCommand /root/ssh-wrapper in /etc/ssh/sshd_config | |
# add logger options when needed | |
log="logger -t ssh-wrapper" | |
# find IP address | |
ip=`echo $SSH_CONNECTION | cut -d " " -f 1` | |
$log $USER login from $ip | |
espeak "$USER just logged in from $ip" > /dev/null 2>&1 | |
$log command: ${SSH_ORIGINAL_COMMAND:-shell} | |
${SSH_ORIGINAL_COMMAND:-shell} | |
$log $USER logout | |
espeak "$USER just logged out" > /dev/null 2>&1 |
#!/bin/bash
# /etc/ssh/sshrc
# Send Email
ip=`echo $SSH_CONNECTION | cut -d " " -f 1`
logger -t ssh-wrapper $USER login from $ip
echo "User $USER just logged in from $ip" | sendemail -q -u "SSH Login" -f "Originator <[email protected]>" -t "Your Name <[email protected]>" -s smtp.server.com &
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://askubuntu.com/questions/10294/run-system-script-on-ssh-login-and-or-logout