Skip to content

Instantly share code, notes, and snippets.

@kokoye2007
Created July 11, 2021 07:19
Show Gist options
  • Save kokoye2007/cc302f4e519f8e84694448a9aca48947 to your computer and use it in GitHub Desktop.
Save kokoye2007/cc302f4e519f8e84694448a9aca48947 to your computer and use it in GitHub Desktop.
SSH - User Login Logout
#! /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
@kokoye2007
Copy link
Author

kokoye2007 commented Jul 11, 2021

#!/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