Score:0

How to log all command ran inside a SSH session by ip for `dash`

br flag

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.

hr flag
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) .
avi7611 avatar
br flag
so is there any way i can make this work for dash or sh shells ?
Ray Butterworth avatar
ck flag
Could you use the `script` command to record the entire session?
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.