A remote system does know my IP. How to monitor which files are accessed?
sudo netstat -tunapl gives me the respective IP, I look for a more detailed information.
One possible solution is to use auditd. This daemon can log the access to files and you can filter them by different criterias.
determinate as which user are accessed files. You can check if you have logins, SMB, NFS.
Install auditd: dnf install auditd or apt-get install auditd audispd-plugins
run the daemon: systemctl -now enable auditd
add rule to monitor all file operations:
auditctl -a exit,always -S open -k file_ops
to add operation for particular directory and specific file operations you can exec something like:
auditctl -w /home/user/git/ -p r -k read_only ops
After -p you can use
r - track Read w - track Write x - track eXecute a - track Attributes to add operation for particular directory and user you can exec something like:
auditctl -w /home/user/git/ -F auid=<userID> -k specific_user ops
To search for specific event you can use something like:
ausearch -i -k <key_name> (search by key)
ausearch -i -u <audit_user_id> (search by user)
In addition to the answer talking about auditd, you could try to use : lsof -Pn to see more details on what process accesses what file or fd (file descriptors).
lsof will show you a lot of informations. There are many options but -Pn is my go-to.lsof will also show you connections, etc (and which pid is using it), which may help in your case if you see one end of it be a remote ip that you find suspicious.Then when you see a specific pid that seems to look at something suspicious, you could even try to strace -f -p pid -o /var/tmp/output_of_strace to "follow" every system calls made by that pid.
-f also follows childs of that pid and not just that pid.-o outputfile redirects the output to a file as it is VERY verbose usuallytail -f /var/tmp/output_of_strace from another terminal if you want to follow it "live")
auditdactivated?