Score:0

Which history file does the command in ssh client commandline go to?

id flag

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?

Arkadiusz Drabczyk avatar
br flag
Do you want to save history on the remote server?
dave_thompson_085 avatar
jp flag
`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](https://serverfault.com/questions/559658/log-commands-executed-over-ssh)
id flag
@ArkadiuszDrabczyk Yes
id flag
@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
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.