If I do ssh user@server and then, inside the bash session, I run whatever, when ssh session is closed these executed commands go to .bash_history file. Simple and clear.
But if I do ssh user@server command, this command isn't logged anywhere. Beyond the reason (I suspect no bash session is spawned), what I want to know is: how can I log what commands have been executed in this manner, then?
ssh user@server commandruns your remote shell (whatever that is: might be bash, might be something else) to execute the command, but it runs this shell as noninteractive. bash maintains and stores command history only when run as interactive. Maybe interactive is what you consider a 'session'. If you use (client) publickey and not (ever) password to authenticate, you can setcommand=in (the relevant line(s) of) theauthorized_keysfile – dave_thompson_085 Jan 12 '22 at 01:00