How To Make A File Write Protected And Undeletable In FreeBSD?

How To Make A File Write Protected And Undeletable In FreeBSD?


This post was last updated on August 1st, 2020 at 10:19 am

FreeBSD operating system has an extra security feature for files called file flags. It provides additional control over files, but not directories. If you set the flag of a file it can not be removed or altered by anyone including root.

The chflag utility can be used to modify the file flags of the listed files as specified by the flag operand. Only root or the owner of a file can enable or disable these flags.

How to write-protect a file

You can write-protect a file by enabling the schg flag on it. To make file1 write-protected, so that no one can edit this file, use the following command in your terminal –

chflags schg file1

To check the current flags set on a file, use –

ls -lo file1

How to enable the undeletable flag on a file

If you enable the undeletable flag on a file. The file can not be deleted by anyone even by root. Set the undeletable flag on a file by using –

chflags sunlink file1

Now again execute the given command to view the flags on a file-

ls -lo file1

Now if you run the command to edit or delete the file1 this says operation not permitted –

To edit or delete this file first you need to turn off these flags.

Remove the immutable or undeletable flag of a file

To disable the write-protected or immutable flag from a file, use the following command  –

chflag noschg file1

Or issue the given command to disable undeletable flag from the file –

chflags nosunlink file1

 Some other files flag in FreeBSD

Apart from these two flags, there are some other flags that can be used by the root user or owner of the file to alter the behavior of a file. A few of them are listed below –

  • arch – set the archived flag
  • sappnd – set the system append-only flag
  • schg – set the system immutable flag
  • sunlnk – set the system undeletable flag
  • uappnd –set the user append-only flag
  • uchg – set the user immutable flag
  • uunlnk –set the user undeletable flag

If you use no before these flags it will disable the flag on a file. To know more about the flags and option that can be used with chflag, see its manual page by using –

man chflag


By enabling a flag you can increase the security of a file. Now if you want something to say on this topic then share your thought with us in the comments below.

Previous GParted wont open despite already installed.
Next [ubuntu] error: internal error: libxenlight state driver is not active

About author

You might also like

How To 0 Comments

PL5000 Debian 30.2-6.x

This post was last updated on June 1st, 2020 at 04:16 pmThanks to Frederik for the following success story: PL5000, 512 MB mem (side note: the PL5000 contains 1 EISA,

How To 0 Comments

How To Extract A Zip File In Linux Using Terminal?

This post was last updated on August 1st, 2020 at 12:26 pmZip is an archive file format that supports lossless data compression. It is available for various platforms. Windows and

Linux Topics 0 Comments

How To Remove/Uninstall Software Packages From Debian, Ubuntu, Linux Mint?

This post was last updated on August 1st, 2020 at 12:21 pmDifferent Linux distribution comes with different tools to manage software packages on it. Debian and its derivative use the


No Comments Yet!

You can be first to comment this post!

Leave a Reply