0

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?

Paul
  • 3,137
Osqui
  • 135
  • Do you want to save history on the remote server? – Arkadiusz Drabczyk Jan 11 '22 at 21:38
  • 2
    ssh user@server command runs 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 set command= in (the relevant line(s) of) the authorized_keys file – dave_thompson_085 Jan 12 '22 at 01:00
  • @ArkadiuszDrabczyk Yes – Osqui Jan 13 '22 at 21:23
  • @dave_thompson_085 Thanks a lot for your clear explanation. So I infer from your words that if I don't use command= option in authorized_keys (nor the ForceCommand option in sshd_config), there's no way to know which (arbitrary) command a ssh client could have executed in every noninteractive session. Mmmm...I don't know if this is something to worry about...thanks anyway – Osqui Jan 13 '22 at 21:26

0 Answers0