Sometimes it is useful to record what commands were executed inside a SSH session by users or applications, and what responses these commands returned. This can be used for auditing or troubleshooting purposes.
Courtesy to John Simpson, a script is provided by him to implement this logging facility on either client side or server side. Note that server side implementation assumes you are using SSH key authentication instead of password authentication, which you should be doing anyway.
Here is the article he wrote about the whole SSH logging idea:
And here is his shell script for server side installation:
Here is an example of what was logged using his script, note that the command attempted to execute was not found (not installed) on the targeted SSH host.
executing sudo dmidecode | grep -i uuid | awk '{print $2}'
========================================
Script started on 2021-10-18 04:23:38+00:00 [<not executed on terminal>]
sudo: dmidecode: command not found
Script done on 2021-10-18 04:23:38+00:00 [COMMAND_EXIT_CODE="0"]