I have inherited a bunch of Linux (Ubuntu Precise) servers and am currently having problems with the ownership of a folder changing to "root" fairly often. We run puppet, which changes the ownership to the user it should be, but something else changes it back a bit later.
I'm currently logging the permissions on the file every 30 seconds to try and narrow down a time to see if there's anything in logs, etc. It's a large busy server, so without more information it's not easy to find anything in logs.
Is there a way in Linux to catch when a file/folder ownership changes and detect the process responsible?
I think you can use audit for specific file/directory or you can write custom rule based on your requirement
Then you can search it using
For eg I used this,create this file /tmp/test and then write some random data
and then execute this command
So the output of this
So if you check the last line of output it will show command executed is vim and with uid=0 which is root
If you want to make these changes persistent across reboot,inside /etc/audit/audit.rules add the entry like this
and make sure auditd service is up and running
For more info you can refer http://www.cyberciti.biz/tips/linux-audit-files-to-see-who-made-changes-to-a-file.html
A quick google reveals inotify api in the Linux kernel.
I can't find any applications that allow you to watch a file directly with inotify. However there is the inotify-tools package which allows you to get access to the api in scripts.
It doesn't by itself tell you who changed what, but you may be able to use this api to build a script to narrow it down. For example, by combining it with lsof and ps
Sorry, there is nothing in the standard Linux system that does logging at such a level. You'll probably have to write a script, however, even that is a hit or miss proposition.
Hmmmm....you might be able to set the immutable bit on the file to protect it and see who complains that it cannot be changed: