I'm a programmer specialising in performant and scalable systems using PHP and Ruby and cooking


Recording SSH sessions

Recently I was tasked with the migration of a website. The client required that I record all steps so that they can repeat any processes in the future. Thinking about this it seemed sensible to just record the entire session so that they could see all potential errors and resolutions.

The solution is really simple, take you normal ssh connection:

$ ssh [user@]hostname

To record this session simply pipe the session to "tee":

$ ssh [user@]hostname | tee -a ssh.log

Tee - read from standard input and write to standard output and files.

The "-a" option tells tee to append all input to the file given, in this case "ssh.log". So what will this look like?

I'm going to show simple test of this using my local machine by connecting, logging in and echoing a test string.

$ ssh harry@localhost | tee -a ssh.log

And the contents of ssh.log:

Last login: Fri May 18 13:37:59 2012  
ukwm142:~ harry$ echo "This is a test"  
This is a test  
ukwm142:~ harry$ logout  

As you can see the log file contains everything after the login is completed.