How can I create session logs of individual SSH sessions?

2

Here is what I am looking for:

A way to log individual SSH sessions on SunOS. I would like to have the files kept separate based upon the hostname of the device I am SSHing into. I am only using the CLI interface so GUI tools will not work. Some of the options I am considering include either using the script command or the screen utility. If someone could explain how they log multiple sessions to multiple devices via an automated method. So for example if you could include either a .bashrc example or a script that I could use so I am not manually entering the same commands every time I login that would be ideal.

I was thinking perhaps a script could first call either screen or script and begin the logging based on the hostname I am SSHing into and then call SSH to start the connection. Thanks!

Mark S.

Posted 2012-06-06T14:29:47.873

Reputation: 1 289

Answers

3

To create a raw logfile of everything that occurs during a session, including screen control escape codes, I would use tee.

In your .bashrc create a function:

myssh () { ssh $1 2>&1 | tee -a ~myusername/logdir/$1.log; }

And then create an alias:

alias ssh=myssh

Now, assuming you have created logdir, anytime you make an ssh connection, the contents of your session will be appended to the logfile based on the connection name.

Don Simon

Posted 2012-06-06T14:29:47.873

Reputation: 444

Do you get a load of control characters, in you log? Back-spaces, and new-line converted to new-line + carage-return. – ctrl-alt-delor – 2016-07-14T10:08:51.867