Recording an SSH session to a log file

I recently required an OpenVox representative to SSH my Elastix (Asterisk PBX) box to configure Caller ID.  Since they were doing this for free and I hadn’t purchased the card directly from OpenVox I wanted to log the session to see what they had done to get it working for future builds.

After searching on the internet I came across an Expert-Exchange post answered by wesly_chen.

Edit /etc/profile (assuming the account default shell is bash/sh) and add:

USER="`id -un`"
LOGNAME=$USER
# log account1 activity#
CURRENT_DATE=`date +%Y%m%d`
if [ $USER = "account1" ] ## the account1 may vary
then
if [ -f /var/log/account1_$CURRENT_DATE ]
then
script -a /var/log/account1_$CURRENT_DATE
else
script /var/log/account1_$CURRENT_DATE
fi
fi

The log file is /var/log/account1_$CURRENT_DATE

Also ensure /etc/ssh/sshd_config has
—-
X11Forwarding no
—-

For more details, do man script