Skip to content

Instantly share code, notes, and snippets.

@veritas06
Last active November 12, 2017 20:25
Show Gist options
  • Save veritas06/062fc53c71c499583810abbd2fd34e4a to your computer and use it in GitHub Desktop.
Save veritas06/062fc53c71c499583810abbd2fd34e4a to your computer and use it in GitHub Desktop.
[Log SSH Session] Begins an SSH session with logging, at \home\<CurrentUser>\Logs\SSH.log #bash #ssh
#!/bin/bash
# Script to log each SSH session
# Create Log Directory
# CurrentUser="whoami" # Not needed
# mkdir "/home/$USER/Logs"
# mkdir "/home/$CurrentUser/Logs/"
# $LogDirectory="/home/$USER/Logs/"
# if [ ! -d "$LogDirectory" ]; then
if [ ! -d "/home/$USER/Logs" ]; then
# mkdir "/home/$USER/Logs"
echo "Log directory not detected. Being created at /home/$USER/Logs."
mkdir "/home/$USER/Logs"
fi
echo "User:" $1 | tee -a "/home/$USER/Logs/SSH.log"
echo "Host:" $2 | tee -a "/home/$USER/Logs/SSH.log"
echo "Log directory detected at /home/$USER/Logs."
date | tee -a "/home/$USER/Logs/SSH.log"; ssh "$1"@"$2" | tee -a "/home/$USER/Logs/SSH.log"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment