Find the answer to your Linux question:
Results 1 to 8 of 8
Hi all.. I want to create a file which never delete from any of command, utility,any user and it should removed only when i format my disk.. Could you any ...
  1. #1
    Just Joined!
    Join Date
    Jan 2007
    Location
    India
    Posts
    10

    Thumbs up how to create never deleting file.

    Hi all..

    I want to create a file which never delete from any of command, utility,any user and it should removed only when i format my disk..

    Could you any one tell me the solution or idea?


    Thanks in advance.
    Ganesh

  2. #2
    Linux Guru techieMoe's Avatar
    Join Date
    Aug 2004
    Location
    Texas
    Posts
    9,496
    I'm curious why you want to do this, but you can make a file untouchable by anyone other than root with chmod 700. I don't know if it's possible to make a file untouchable by root user though.
    Registered Linux user #270181
    TechieMoe's Tech Rants

  3. #3
    Linux Guru
    Join Date
    Nov 2004
    Posts
    6,110
    I have seen occasionally where a logfile can be written to but not read - chmod 744 somefile. This means that users only have a one way interaction with a file.

  4. #4
    Trusted Penguin Cabhan's Avatar
    Join Date
    Jan 2005
    Location
    Seattle, WA, USA
    Posts
    3,230
    As far as I know, this is rather impossible, except on the kernel level.

    The reason for this is simple: first off, the root user has 777 permissions on everything in the system (except for files that the kernel prohibits this on). Secondly, even if you are not allowed to write to a file, if you have write permissions on a directory, you can delete files inside of that directory.

    Maybe there is some sort of program / kernel module that allows you to specially protect files? See if you can find anything: I'd be interested.
    DISTRO=Arch
    Registered Linux User #388732

  5. #5
    oz
    oz is offline
    forum.guy
    Join Date
    May 2004
    Location
    arch linux
    Posts
    18,095
    I was thinking you could do it with chattr and the i attribute:

    Code:
    chattr +i filename
    The file would still deletable by root but only after he removes the immutable flag.
    oz

    new members/users: read this first | new member faq
    no private messages requesting computer support - post them on the forums!
    please use the "report post" button to alert our forum admins to problematic posts rather than responding to them yourself.

  6. #6
    Linux Guru anomie's Avatar
    Join Date
    Mar 2005
    Location
    Texas
    Posts
    1,692
    chattr +i (immutable) is the way to do this.

    But that alone isn't enough. You need to make it so that even root can not remove the immutable attribute. To do this, you need lcap.

    Protecting the file would work like this:
    1. Make it immutable using chattr.
    2. Remove the immutable capability (and a couple others, explained in the manpage) altogether using lcap.


    Now no one, not even root, can modify or delete that file. In order to delete it, a reboot would have to occur (in order to get the ability to change immutable attributes back). And you need to be monitoring for/preventing reboots anyway.

  7. #7
    Trusted Penguin Cabhan's Avatar
    Join Date
    Jan 2005
    Location
    Seattle, WA, USA
    Posts
    3,230
    Interestingly, I've never used chattr before. Cool beans.

    One thing I do note is that (according to the man page, at least), it only works with ext* filesystems. Is there a comparable program for ReiserFS, etc.?
    DISTRO=Arch
    Registered Linux User #388732

  8. #8
    Linux Guru anomie's Avatar
    Join Date
    Mar 2005
    Location
    Texas
    Posts
    1,692
    Yep, chattr was designed for ext2/3 filesystems. In BSD land there is (comparable) chflags for ufs.

    I am not sure about reiserfs. (I don't use it/have it.) I did a cursory search and didn't come up with much.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...