Ssh – How to see what a user is doing in their ssh session

administrationlinuxsshw

I logged into a server as root and did w, this let me see that a user was editing a file.

someuser  pts/5    10.117.0.53      14:03    3:25   1.20s  1.14s vi somefile.py

Then I disconnected, and reconnected as root again later. I did a w again but this time it showed something different.

someuser  pts/5    10.117.0.53      14:03    5:20   0.20s  0.02s sshd: someuser [priv]

I can tell from the other fields that this is the same user, but this time what they're doing is hidden.

Why did it become hidden? How do I see what they're doing?

Best Answer

If a user is using bash, you can add to his /etc/bash.bashrc:

readonly PROMPT_COMMAND='history -a >(logger -t "commandlog $USER[$PWD] $SSH_CONNECTION")'

This will log all the user commands to syslog.

I would configure syslogto forward the logs to a locked down central syslog server, so in case of hacking or a rogue sysadmin, they would not be able to tamper with evidence.

Related Question