The Wonderful World Of Linux

Linux, Mac, Web Hosting and Whatnot

Record Your SSH Session

| Comments

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:

1
ssh [email protected] | 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.

1
2
3
4
Last login: Wed Jan 30 10:19:44 2013
[email protected] [~]# echo "Hello"
Hello
[email protected] [~]# logout

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

1
ssh [email protected] | tee -a /path/to/file

Set the execution bits and you can now run sshlog [email protected] 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:

1
alias ssh='sshlog'

Comments