48

How can I view the command history of another user?

I am an admin on my machine. I can see normal history by viewing /home/user_name/.bash_history but I can't see commands of that user_name when they were doing sudo.

Is there a way to view all command executed by one user?

bertieb
  • 7,344
  • 36
  • 42
  • 54
Sean Nguyen
  • 945
  • 2
  • 10
  • 10
  • 1
    Steal his password :) or by social engineering ..If you are not root, and your account is set up in a way that you can't get go/read other user's home/files you are pretty much restricted. – ring bearer Jul 11 '11 at 21:50
  • 11
    "I am an admin on my machine." –  Jul 11 '11 at 21:52

7 Answers7

39

On Debian-based operating systems, doing tail /var/log/auth.log | grep username should give you a user's sudo history. I don't believe there is a way to get a unified command history of a user's normal + sudo commands.

On RHEL-based operating systems, you would need to check /var/log/secure instead of /var/log/auth.log.

themanatuf
  • 103
  • 3
Kerin
  • 505
  • 4
  • 5
19

Just tested the following, and it worked like a charm.

sudo vim /home/USER_YOU_WANT_TO_VIEW/.bash_history
Excellll
  • 12,627
  • 11
  • 51
  • 78
Tyson
  • 199
  • 1
  • 2
  • 2
    S/he's already aware of this command. From the original question: "I can see normal history by viewing /home/user_name/.bash_history but i can't see commands of that "user_name" when they were doing sudo." – Michael Thompson Feb 18 '16 at 18:58
4

use below command

sysdig -c spy_users

if sysdig not installed, install here

sachin_ur
  • 141
  • 3
3

If the user issued a command as in sudo somecommand, the command will appear in the system log.

If the user spawned a shell with eg, sudo -s, sudo su, sudo sh, etc, then the command may appear in the history of the root user, that is, in /root/.bash_history or similar.

bdonlan
  • 1,563
  • 1
  • 14
  • 22
1

# zless /var/log/auth* is your friend here. It opens even the gzipped files. You can jump between those with :n forwards or :p backwards.

Alternatively, you can use # journalctl -f -l SYSLOG_FACILITY=10 for instance. Read more about this on the Arch Linux wiki

AdamKalisz
  • 565
  • 5
  • 7
0

Maybe this link has a value to you : http://www.sudo.ws/pipermail/sudo-users/2000-March/000052.html

But you should mind that leaving no trace in bash_history is just a matter of starting a command with a space etcpp. The history is a helper, not a logging-tool.

Greetings from Germany, Daniel Leschkowski

-1

The logic applies to many other objectives.
And how to read .sh_history of each user from /home/ filesystem? What if there are thousands of them?

#!/bin/ksh
last |head -10|awk '{print $1}'|
 while IFS= read -r line
 do
su - "$line" -c 'tail .sh_history'
 done

Here is the script.

Glorfindel
  • 4,089
  • 8
  • 24
  • 37
Rogi
  • 1
  • 1