Linux

Categorized | Security

Protect your Linux files by an accidental deletion

You can protect your most important files from accidental deletion by giving them a “sticky bit” attribute: chmod +t filename

Author Profile

T4L ;

Other posts by T4L

Author's web site



Are you satisfied with this blog?
Why not subscribe our RSS Feed? you will always get the latest post.


3 Comments

  1. syphus

    That will protect files not owned by you (only from being renamed or deleted), another way to do it that would protect any file (from rename / delete / modification) is:

    chattr +i

    I think this is specific to ext2/3/4

    1
  2. syphus

    Actually, sticky bit only works like that on directories, from the man-page:

    RESTRICTED DELETION FLAG OR STICKY BIT
    The restricted deletion flag or sticky bit is a single bit, whose interpretation depends on the file type. For directories, it prevents unprivileged users from
    removing or renaming a file in the directory unless they own the file or the directory; this is called the restricted deletion flag for the directory, and is com?
    monly found on world-writable directories like /tmp. For regular files on some older systems, the bit saves the program’s text image on the swap device so it will
    load more quickly when run; this is called the sticky bit.

    2
  3. Live

    Or you can do this:

    sudo chmod 1755 file_or_folder_name, normally we just type:

    sudo chmod 755 file_or_folder_name, but the presence of 1 makes it the same as chmod +t filename as stated above.

    Then apply it recursively to the contents of a folder, so finally

    sudo chmod -R 1755 file_or_folder_name

    3

Leave A Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>