The Wonderful World of Linux A mostly dead cpanel/linux blog

Record Your SSH Session

If you’re troubleshooting an issue on your server and you suck at taking documention, you can simply pipe the SSH output into a file for review later:

ssh | tee -a /path/to/file

What is really cool about this method (As opposed to just saving the history) is that it will also save the result of the command.

Last login: Wed Jan 30 10:19:44 2013
root@hydra [~]# echo "Hello"
root@hydra [~]# logout

You can also automate this. Create a file in your ~/bin/ directory called sshlog or similar and input the following code:

ssh $@ | tee -a /path/to/file

Set the execution bits and you can now run sshlog root@server and any other flags you would normally run with SSH and it will be appended to your file (as defined by the -a flag in tee). If you want this to always run when you kick of ssh, simply create an alias:

alias ssh='sshlog'