Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I've got 4 specific files that seem to keep disappearing from a user's home directory. As far as we know, there are no cronjobs or other automated tasks that would be removing them. I've setup auditd on them but the logs aren't really showing anything of interest. I can see our backup utility accessing them every night until the point they aren't there anymore, but nothing else. Is there anything that would be causing those files to be removed that would get around auditd?

The files in question are these:

/home/username/.bashrc
/home/username/.bash_profile

as well as a couple of files in that user's .ssh directory. Copies of these files placed into a subfolder called "keepers" get deleted at the same time as well. Changing the permissions on them to 000 and having them owned by root hasn't helped.

I've currently got inotifywait setup to log create,delete,move on that subfolder, so hopefully that will turn up something, although it doesn't log much aside from when it happened, not what caused it.

share|improve this question
1  
Please add their names and paths to your post, it may help. –  Shadok Aug 23 '11 at 13:18
2  
Also posting auditd logs might be helpful. –  Janne Pikkarainen Aug 23 '11 at 13:23
2  
Also you might try creating the files owned as root and chmod 000 to see if they still get removed (or if that causes something else to complain/error out). –  polynomial Aug 28 '11 at 6:44
4  
In addition to chmod 0000, you could try chattr +i to try to prevent even root from removing it –  mer Sep 12 '11 at 13:39
1  
be aware that chattr just helps on ext filesystems. but a chattr should help. :-) You can also use SELINUX instead of chattr to stop those files from being modified. but IMHO the deletion must come from a process or user. –  JMW Sep 12 '11 at 16:15
show 4 more comments

6 Answers

up vote 14 down vote accepted
+200

You can use systemtap to show all PIDs that are trying to use unlink() on the inode of .bashrc and .bash_profile files.

Install systemtap and the debug symbols for your kernel.

Create a file with name unlink.stap with the following content:

probe syscall.unlink
{
    printf ("%s(%d) unlink (%s) userID(%d)\n", execname(), pid(), argstr, uid())
}

Then run it with sudo stap unlink.stap

You can also use inotify to see when the file is deleted.

share|improve this answer
add comment

To prevent losing the files and their content you can setup libtrash via LD_PRELOAD. Using libtrash you can do number of things but those that might be interesting to you are

INTERCEPT_UNLINK
INTERCEPT_RENAME
INTERCEPT_FOPEN
INTERCEPT_OPEN

Good article about libtrash can be found here

Other thing you mention, that you chowned files to root and they still got removed. It is because /home/username is owned by username; and if dir has say mod 755; then any file or dir in that dir owned by no matter who can be removed by user; even if it is roots file or dir. It's basically due to fact that removing file in dir means changing the dir contents and user has 7 (in 755) of that dir so he can do whatever he wants.

There are ways to block this as other people already suggested via chattr on ext file systems to set files as immutable (+i). Then one would need to unset the immutable flag before making any changes to file/dir which has the +i flag. Immutable flag / chattr can only be used by root.

share|improve this answer
add comment

More seems like an intruder, who is doing a find /home/user -name filename -exec rm -f {} \; after all his sneaking :). Just guessing, because you mentioned that the backup files are also getting deleted.

share|improve this answer
add comment

We use bash logout scripts (~/.bash_logout) to clean out certain files upon logout - you might check to see if you have that setup, perhaps with a fat-fingered glob in it.

share|improve this answer
add comment

in addition to micea's answer, you can chattr +i the files as root and see if anything logs an error when trying to remove them.

share|improve this answer
add comment

Are you absolutely sure the user himself is not (accidentally) deleting them ?

I had some clueless (Windows) users with the same problem. Turned out that they deleted those files themselves every time they visited their home-dir with a ftp client. They noticed the .xxxx files (the ftp client didn't hide them) and removed the "clutter".

It never occurred to me they did it to themselves until one of them complained about the spontaneously re-appearing files he had deleted several days before.

share|improve this answer
1  
Believe me, I'd love it to be this easy. –  Chad P Sep 12 '11 at 14:12
    
This was funny :) –  snap Sep 12 '11 at 14:13
3  
It's funny now.... Not so much when it was happening and I couldn't figure out what was going on. @Chad P: Please let us know what you find. I find this one quite curious. –  Tonny Sep 12 '11 at 14:35
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.