2

I hate programs like Flash and others that install crappy settings on /Library/LaunchDaemons and /Library/LaunchAgents, stuff to launch daemons that check for updates of flash.

I generally replace the files these apps put there with empty files and change permissions to 000 using chmod.

This works fine but every time I have to install an update, the update installation removes the locked files with their crappy files again.

Is there a way to lock these files in a way that any installation can change?

thanks

1 Answer 1

0

You can do it using chflags. Try this way:

chflags uchg filename

Once type this command, filename can only be modified by you. Others users (root included) can't change it.

To revert the changes, use:

chflags nouchg filename

See the example below:

✔ jherran@computer: ~/temp $ touch filename
✔ jherran@computer: ~/temp $ chflags uchg filename
✔ jherran@computer: ~/temp $ sudo su
Password:
✔ root@computer: /Users/jherran/temp # rm filename
rm: cannot remove ‘filename’: Operation not permitted
✘-1 root@computer: /Users/jherran/temp # rm -f filename
rm: cannot remove ‘filename’: Operation not permitted
✘-1 root@computer: /Users/jherran/temp #
9
  • the question is this: because the file is on /Library/LaunchDaemons I have to type sudo chflags uchg filename. If the installation asks for my root password, as it does, isn't this command useless?
    – Duck
    Commented Jun 15, 2015 at 11:06
  • If the installation use root, you can use chflags with any other user, that way, the root can't alter it. Another way, create a new user just for this task and nor your installations, nor root's will be able to alter that files.
    – jherran
    Commented Jun 15, 2015 at 11:13
  • I cannot use chflags with another user on a directory that belongs to the system. What you mean is that I use chmod to change the user ownership, right? But if the installer has root access it can still remove my file and add another one.
    – Duck
    Commented Jun 15, 2015 at 11:50
  • Yes, use chmod to change file user, then chflags with that user. After that the installer (no matter if has root access) won't be able to remove that file.
    – jherran
    Commented Jun 15, 2015 at 12:07
  • @jherran, You have made statements in your answer that are not accurate, root absolutely can change the file afterwards and also delete it as well. Commented Jun 15, 2015 at 12:54

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .