Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

All, I have an Ubuntu host that accepts SSH connections. How can I log all commands that are run on a specific account that logs in via SSH?


share|improve this question

Maybe you can make sshd use a logging shell like rootsh?

share|improve this answer
how do you install rootsh on Ubuntu – Lexicon Mar 14 '12 at 20:14
@Lexicon: AFAIK there's no already-compiled deb package available, just a source archive. Installing an application from source is described here, for example. The INSTALL file located in the source archive describes the different config options you can set before compiling it. – tohuwawohu Mar 14 '12 at 21:46

You can try with snoopy. After you install it, will logs all input command that calls execve to syslog. you'll only find it in the repos for hardy and precise.

You can install it from here.

share|improve this answer

I don't think SSHD logs commands while the user is logged in.

you can check who logged in by checking


and cross reference it to their history


history will have commands local or remote though.

share|improve this answer
auth.log contains session opened and closed info but not commands that were ran while logged in. .Bash_history only show local commands, nothing through the ssh session (at least from what I can tell). – Lexicon Mar 14 '12 at 14:38
~/.bash_history will not work as the user can alter the file. – bodhi.zazen Mar 14 '12 at 17:19
.bash_history is not showing what happens via ssh. – Lexicon Mar 22 '12 at 15:35

I have a similar problem and wrote the tool log-user-session which stores all shell output into a root-only accessible session log file. It can be enabled via forced command on sshd_conf or ~/.ssh/authorized keys (see documentation).

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.