Last active
November 12, 2017 20:25
-
-
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
This file contains 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/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