veritas06
11/12/2017 - 8:19 PM

[Log SSH Session] Begins an SSH session with logging, at \home\<CurrentUser>\Logs\SSH.log #bash #ssh

[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"