Ubuntu – How to make files protected

filespermissions

How to make some file that contains crucial data protected? For instance, suppose I have some files that are important, is there any method or strategy to make these kind of file more protected on Ubuntu? I even want to make some files ask for a password whenever someone tries to open it. Does it affect the version of Ubuntu in terms of security policy? May I use any encryption algorithm externally? Regards.

Best Answer

The best method you have is chattr +i {file}. This sets the immutable attribute and then a file can not be modified, deleted, renamed or a hardlink created by anyone including root.

The only person that can edit the file is root. (S)he has to undo this by removing the immutable bit: chattr -i {file} and can then do whatever with the file. Setting the +i again locks the file from any modification.

This will not prevent from formatting the partition where the file is stored though. It will prevent theft of the file.


You can even do this on a complete mountpoint if you want:

chattr +i -R /discworld

would make the whole "discworld" and anything in it immutable (chattr -i -R /discworld to undo it ;) )


Related Question