0

Hi I am able to log all the commands ran by a user on my ssh server using these lines in my /etc/profile.

whoami="$(whoami)@$(echo $SSH_CONNECTION | awk '{print $1}')"                                                                                                  
export PROMPT_COMMAND='RETRN_VAL=$?;logger -p local3.debug "$whoami [$$]: $(history 1 | sed "s/^[ ]*[0-9]\+[ ]*//" ) [$RETRN_VAL]"'

now my problem is when i ssh into the server and then type sh/dash a new shell opens and nothing is logged after that, it only logs everything outside the sh shell.

i have tried putting the above code into $HOME/.profile and other files like .bash_profile .bashrc but no luck.

PS: The rbash shell is also logging the commands, but the sh and dash wont.

  • 2
    AFAIK the `dash` shell (which provides /bin/sh on Ubuntu by default) doesn't support either the `PROMPT_COMMAND` or `history` commands. See for example [fc built in missing from dash ( i.e.,dash shell history doesn't work)?](https://askubuntu.com/questions/1027012/fc-built-in-missing-from-dash-i-e-dash-shell-history-doesnt-work) . – steeldriver Oct 10 '22 at 12:43
  • so is there any way i can make this work for dash or sh shells ? – avi7611 Oct 11 '22 at 05:10
  • Could you use the `script` command to record the entire session? – Ray Butterworth Oct 25 '22 at 03:09

0 Answers0