7

Can I see what other users type/execute via SSH in my server via bash or shell?

2
2

Read the user history file from their home directory.

less .bash_history

And if needed then with timestamps too on history command.

echo 'export HISTTIMEFORMAT="%d/%m/%y %T "' >> ~/.bashrc

source ~/.bashrc
0

Without changing their shell, the best bet would be to read their shell's history file in their home directory.

0

I would do something like this:

ssh -l user 10.10.1.1 cat ~/.bash_history
2
  • 3
    If it's your machine, why would you SSH back to it to look at a local history file? – thrig Mar 22 '17 at 13:49
  • @thrig, this uses SSH from another machine to display commands executed. It's pretty close to the question title. ;) – Wildcard Jul 8 '17 at 5:00
0

Simply type:

more ~/.bash_history

This will show each and every command that has been executed using an SSH session except the one which you are currently using (if any).

Note: Tested on Solaris 11.3, Oracle Linux 7.2 and Ubuntu 16.04

3
  • I'm not sure, but I don't think this address the question of what other users type. – Jeff Schaller Jun 12 '17 at 15:25
  • I tried executing commands on my server using SSH session from another server. It is listing all the commands I executed using that SSH session. – Amit24x7 Jun 12 '17 at 15:34
  • emphasis on other users – Jeff Schaller Jun 12 '17 at 15:48
0

Tools are available now that may not have been when the question was asked 2+ years ago. This may not be exactly what OP was asking for either, but it could be valuable for other readers.

You may want to consider tlog and the cockpit-session-recording package. Red Hat seems to be promoting these tools with RHEL8.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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