A ferramenta para fazer isso é auditd , que é
the userspace component to the Linux Auditing System. It's responsible for writing audit records to the disk. Viewing the logs is done with the ausearch or aureport utilities. Configuring the audit rules is done with the auditctl utility. During startup, the rules in /etc/audit/audit.rules are read by auditctl. The audit daemon itself has some configuration options that the admin may wish to customize. They are found in the auditd.conf file.
(do Manual ). Para detectar um arquivo que está sendo apagado, depois de instalar o pacote auditd e iniciá-lo, você audita a pasta contida do arquivo em questão, da seguinte forma:
$ touch zz $ sudo auditctl -w /home/me -p wa $ rm /home/me/zz $ sudo cat /var/log/audit/audit.log type=DAEMON_START msg=audit(1491310210.803:235): auditd start, ver=2.4.5 format=raw kernel=4.8.0-45-generic auid=4294967295 pid=29913 subj=unconfined res=success type=USER_AUTH msg=audit(1491310280.366:26): pid=30060 uid=1000 auid=1000 ses=2 msg='op=PAM:authentication acct="e" exe="/usr/bin/sudo" hostname=? addr=? terminal=/dev/pts/6 res=success' type=USER_ACCT msg=audit(1491310280.366:27): pid=30060 uid=1000 auid=1000 ses=2 msg='op=PAM:accounting acct="me" exe="/usr/bin/sudo" hostname=? addr=? terminal=/dev/pts/6 res=success' type=USER_CMD msg=audit(1491310280.366:28): pid=30060 uid=1000 auid=1000 ses=2 msg='cwd="/home/me" cmd=617564697463746C202D77202F686F6D652F6D6172696F202D70207761 terminal=pts/6 res=success' type=CRED_REFR msg=audit(1491310280.366:29): pid=30060 uid=0 auid=1000 ses=2 msg='op=PAM:setcred acct="root" exe="/usr/bin/sudo" hostname=? addr=? terminal=/dev/pts/6 res=success' type=USER_START msg=audit(1491310280.366:30): pid=30060 uid=0 auid=1000 ses=2 msg='op=PAM:session_open acct="root" exe="/usr/bin/sudo" hostname=? addr=? terminal=/dev/pts/6 res=success' type=CONFIG_CHANGE msg=audit(1491310280.390:31): auid=1000 ses=2 op="add_rule" key=(null) list=4 res=1 type=USER_END msg=audit(1491310280.390:32): pid=30060 uid=0 auid=1000 ses=2 msg='op=PAM:session_close acct="root" exe="/usr/bin/sudo" hostname=? addr=? terminal=/dev/pts/6 res=success' type=CRED_DISP msg=audit(1491310280.390:33): pid=30060 uid=0 auid=1000 ses=2 msg='op=PAM:setcred acct="root" exe="/usr/bin/sudo" hostname=? addr=? terminal=/dev/pts/6 res=success' type=SYSCALL msg=audit(1491310299.535:34): arch=c000003e syscall=263 success=yes exit=0 a0=ffffff9c a1=21b0000 a2=0 a3=15e items=2 ppid=2441 pid=30087 auid=1000 uid=1000 gid=1000 euid=1000 suid=1000 fsuid=1000 egid=1000 sgid=1000 fsgid=1000 tty=pts6 ses=2 comm="rm" exe="/bin/rm" key=(null) type=CWD msg=audit(1491310299.535:34): cwd="/home/me" type=PATH msg=audit(1491310299.535:34): item=0 name="/home/me" inode=23199747 dev=fd:00 mode=040755 ouid=1000 ogid=1000 rdev=00:00 nametype=PARENT type=PATH msg=audit(1491310299.535:34): item=1 name="zz" inode=23205547 dev=fd:00 mode=0100664 ouid=1000 ogid=1000 rdev=00:00 nametype=DELETE type=PROCTITLE msg=audit(1491310299.535:34): proctitle=726D007A7A type=USER_CMD msg=audit(1491310321.131:35): pid=30120 uid=1000 auid=1000 ses=2 msg='cwd="/home/me" cmd=636174202F7661722F6C6F672F61756469742F61756469742E6C6F67 terminal=pts/6 res=success' type=CRED_REFR msg=audit(1491310321.131:36): pid=30120 uid=0 auid=1000 ses=2 msg='op=PAM:setcred acct="root" exe="/usr/bin/sudo" hostname=? addr=? terminal=/dev/pts/6 res=success' type=USER_START msg=audit(1491310321.131:37): pid=30120 uid=0 auid=1000 ses=2 msg='op=PAM:session_open acct="root" exe="/usr/bin/sudo" hostname=? addr=? terminal=/dev/pts/6 res=success'
Eu usei o negrito para o evento de exclusão relevante, onde você pode ver facilmente o PPID, o PID e o usuário que executou a exclusão.