• Contact
  • Contact Us
  • Disclamer
  • Home 1
  • Home 2
  • Home 3
  • Privacy Policy
Friday, May 9, 2025
How VPS - How to use/setup VPS
  • Login
  • Home
  • Management guides
    • Web servers software
      • Directadmin
      • Hocvps Script
      • Centmin Mod
      • CWP
      • Kloxo-MR
      • Plesk
    • Control Panels
    • Securing VPS/Servers
      • SSL Certificates
      • Upgrading
      • Authentication
  • Operating System
    • CentOS
    • Fedora
    • Debian
    • Linux
    • Arch
    • BSD
    • CoreOS
  • Reviews
  • Coupon
    • Domain Coupon
    • Hosting Coupon
No Result
View All Result
  • Home
  • Management guides
    • Web servers software
      • Directadmin
      • Hocvps Script
      • Centmin Mod
      • CWP
      • Kloxo-MR
      • Plesk
    • Control Panels
    • Securing VPS/Servers
      • SSL Certificates
      • Upgrading
      • Authentication
  • Operating System
    • CentOS
    • Fedora
    • Debian
    • Linux
    • Arch
    • BSD
    • CoreOS
  • Reviews
  • Coupon
    • Domain Coupon
    • Hosting Coupon
No Result
View All Result
How VPS - How to use/setup VPS
No Result
View All Result
Home Operating System Linux

How to Make File and Directory Undeletable, Even By Root in Linux

How VPS by How VPS
November 2, 2018
in Linux, Operating System
0
0
SHARES
55
VIEWS
Share on FacebookShare on Twitter

Contents

  1. How to Make File Undeletable in Linux
  2. How to Recursively Make Directory Undeletable in Linux

On Unix-like operating systems including Linux, root is the account or user name that by default can modify all directories and files on a system. In this article, we’ll show how to make directories or files unremovable even by the root user in Linux.

To make a file undeletable by any system user, including root, you need to make it unmodifiable using using the chattr command. This command changes file attributes on a Linux file system.

How to Make File Undeletable in Linux

The command below makes /backups/passwd file immutable (or undeletable). This implies that the file can’t be modified in any way: it can’t be deleted or renamed. You can’t even create a link to it and no data can be written to the file as well.

Note that you need superuser privileges to set or remove this attribute, using the sudo command:

$ sudo chattr +i /backups/passwd
OR
$ sudo chattr +i -V /backups/passwd
How to Make File and Directory Undeletable, Even By Root in Linux

Make File Undeletable in Linux

To view attributes of a file, use the lsattr command as shown.

$ lsattr /backups/passwd 
How to Make File and Directory Undeletable, Even By Root in Linux

View Linux File Attributes

Now try to remove the immutable file, both as a normal user and as a root.

$ rm /backups/passwd
$ sudo rm /backups/passwd
How to Make File and Directory Undeletable, Even By Root in Linux

Delete Immutable File in Linux

How to Recursively Make Directory Undeletable in Linux

Using the -R flag, you can recursively change attributes of directories and their contents as follows.

$ sudo chattr +i -RV /backups/  
How to Make File and Directory Undeletable, Even By Root in Linux

Make Directory Undeletable in Linux

To make a file mutable again, use -i sign to remove the above attribute, as follows.

$ sudo chattr -i /backups/ passwd

For more information, read this article: 5 ‘chattr’ Commands to Make Important Files IMMUTABLE (Unchangeable) in Linux

You will find these related article useful:

  1. How to Manage Users and Groups in Linux
  2. Managing Users & Groups and Enabling sudo Access on Users
  3. How to Find Files With SUID and SGID Permissions in Linux
  4. Translate rwx Permissions into Octal Format in Linux

That’s it! In this article, we showed how to make files unremovable even by the root user in Linux. You can ask any questions via the feedback form below.

Source: tecmint.com

Tags: Linux Commandslinux guidelinux vps setup guide
Previous Post

10 Interesting Linux Command Line Tricks and Tips Worth Knowing

Next Post

Disable Certain Package Updates using YUM in RHEL / CentOS / Fedora

Next Post

Disable Certain Package Updates using YUM in RHEL / CentOS / Fedora

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

No Result
View All Result

Recent Post

Install Imagemagick on CentOS
CentOS

Install Imagemagick on CentOS

by How VPS
June 28, 2023
0

This is how I installed Imagemagick on a vanilla CentOS server Start off by installing the prerequisites yum install php-pear...

Read more
how to Check phpinfo

How to Check phpinfo of Hosting or VPS?

June 28, 2023
Failed to download metadata for repo 'appstream' on Centos 8

How to fix error: Failed to download metadata for repo ‘appstream’ on Centos 8

February 25, 2022
How to Fix MySQL Error "Plugin 'InnoDB' registration as a STORAGE ENGINE failed"?

How to Fix MySQL Error “Plugin ‘InnoDB’ registration as a STORAGE ENGINE failed”?

November 17, 2020
How to optimize Mysql or MariaDB

How to optimize Mysql or MariaDB

November 3, 2020

Recent News

  • Install Imagemagick on CentOS
  • How to Check phpinfo of Hosting or VPS?
  • How to fix error: Failed to download metadata for repo ‘appstream’ on Centos 8

Category

  • Arch
  • Authentication
  • Backups
  • BSD
  • Centmin Mod
  • CentOS
  • Control Panels
  • CoreOS
  • CWP
  • Debian
  • Directadmin
  • Encryption
  • Fedora
  • Firewalls
  • Hocvps Script
  • Hosting providers
  • Kloxo-MR
  • Linux
  • Mitigations
  • Operating System
  • Plesk
  • Reviews
  • Securing VPS/Servers
  • Security Patches
  • SSL Certificates
  • Uncategorized
  • Upgrading
  • VPS/Servers management guides
  • Vulnerability Detection
  • Web servers software
  • Webhosting Control Panel
  • About
  • Advertise
  • Careers
  • Contact

© 2025 JNews - Premium WordPress news & magazine theme by Jegtheme.

No Result
View All Result
  • Home
  • Management guides
    • Web servers software
      • Directadmin
      • Hocvps Script
      • Centmin Mod
      • CWP
      • Kloxo-MR
      • Plesk
    • Control Panels
    • Securing VPS/Servers
      • SSL Certificates
      • Upgrading
      • Authentication
  • Operating System
    • CentOS
    • Fedora
    • Debian
    • Linux
    • Arch
    • BSD
    • CoreOS
  • Reviews
  • Coupon
    • Domain Coupon
    • Hosting Coupon

© 2025 JNews - Premium WordPress news & magazine theme by Jegtheme.

Welcome Back!

Login to your account below

Forgotten Password?

Retrieve your password

Please enter your username or email address to reset your password.

Log In
Thabet