Can I see what other users type/execute via SSH in my server via bash or shell?
5 Answers
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
Without changing their shell, the best bet would be to read their shell's history file in their home directory.
I would do something like this:
ssh -l user 10.10.1.1 cat ~/.bash_history
-
3If it's your machine, why would you SSH back to it to look at a local history file?thrig– thrig2017-03-22 13:49:23 +00:00Commented Mar 22, 2017 at 13:49
-
@thrig, this uses SSH from another machine to display commands executed. It's pretty close to the question title. ;)Wildcard– Wildcard2017-07-08 05:00:46 +00:00Commented Jul 8, 2017 at 5:00
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
-
I'm not sure, but I don't think this address the question of what other users type.2017-06-12 15:25:10 +00:00Commented Jun 12, 2017 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– Amit24x72017-06-12 15:34:30 +00:00Commented Jun 12, 2017 at 15:34
-
emphasis on other users2017-06-12 15:48:28 +00:00Commented Jun 12, 2017 at 15:48
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.