Score:2

Save commands used in shell to a file

tw flag

Someone is going to connect to my server and type some commands into the terminal. But after finishing his work, he deletes bash_history.

I am looking for a way to save every command entered into the terminal in a file so that if bash_history is deleted, these commands will be saved in another file automatically.

Score:4
jm flag

The correct answer is to enable auditd with a rule like -a exit,always -F arch=b64 -F euid=0 -S execve in place. This will not catch everything but it is close. You will also have to monitor the audit log files closely as they will grow very quickly.

You might be able to come close by setting HISTFILE to record to a directory that is write-only. The user can re-define HISTFILE if he is aware of what is happening. You will need to investigate setting ACL's on a directory to make it read-only. It is possible and I've done it but I am not going to try to re-create the setfacl necessary for it.

Final answer is that if you don't trust the user they should now have access to your server. They definitely shouldn't have privileged access without a lot of trust involved.

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.