Is it possible for the root user in Linux to have a real-time (or close to real-time) view of the shell commands being run by another user logged in via a terminal or SSH? Obviously they're stored in .bash_history, but that's only saved when the user logs off and can be disabled, too.
Edit: ideally something that can easily be switched on and off.
as root, you could replace their shell with a simple wrapper script that logged their commands before passing them to the real shell. This would only work prior to them logging in.
Use sniffy if you want to break into the user's session or
screen -x
if you have cooperation.Be aware though, that spying on your users might be subject to regulations or even outright illegal depending on your local legislation.
Changing the shell is very trivial to circumvent, patching the shell itself is better, but you have to patch all shells. Our favourite cracker uses this, as a bonus he doesn't bother himself with disabling bash_history.
Snoopy is a wrapper around exec functions, and logs any external binary that is executed(not shell builtins)
@David Schmitt's suggestion sniffy uses a better method, it taps the pseudoterminal.
ttysnoop uses the same method, but it is unmaintained. (I probably had issues making it log ssh connections, can't rememeber)
You can try patching ssh to log a session, but that patch is old.
pseudopod and rootsh can be used for logging legitimate sudos. And shwatcr is another thing to monitor logins.
If you're being cooperative, you can use GNU screen between two users - have one establish the screen session, then have the other join using
screen -x
.If you want root to "spy" on other users without their knowledge, the best and most efficient solution might be keylogger software/hardware.
Sysdig is powerful tool of system-level exploration - this is what you want ;)
example:
sysdig -i spy_users
Category: Security
spy_users Display interactive user activity
lists every command that users launch interactively (e.g. from bash) and every directory users visit
You could try the bash-BOFH patch. Search around for the patch.
I wrote a method to log all 'bash' commands/builtins into a text-file or a 'syslog' server without using a patch or a special executable tool.
It is very easy to deploy, as it is a simple shellscript that need to be called once at the initialization of the 'bash'.
See the method here: http://blog.pointsoftware.ch/index.php/howto-bash-audit-command-logger
Seems to work pretty well if you don't mind sorting through a bunch of line breaks.
Snoopy is intended for lightweight command logging.
If you want live view of commands executed on your system, this may be it. Warning: snoopy is not proper audit solution and can easily be circumvented.
However, if you desire to see every character typed into the terminal, then you will have to use another tool.
Disclosure: I am current snoopy maintainer.
try this export HISTTIMEFORMAT="%T " run a couple of commands and "history" afterwards...