Linux – How does Unix implement file permissions

filesystemslinuxpermissions

I have a text file named foo.txt with root permission in one Linux distribution. I copied it to another Linux distribution on another computer.

Would file permissions be still maintained for foo.txt?

If yes, how does Unix/Linux linux know, and duplicate the permissions of the file?

Does it add extra bytes (which indicates the permissions) to the file?

Best Answer

To add Eric's answer (don't have rep to comment), permissions are not stored in file but file's inode (filesystem's pointer to the file's physical location on disk) as metadata along with owner and timestamps. This means that copying file to non-POSIX filesystem like NTFS or FAT will drop the permission and owner data.

File owner and group is just a pair of numbers, user ID (UID) and group ID (GID) respectively. Root UID is 0 as standard so file will show up as owned by root on (almost) every unix-compliant system. On the other hand, non-root owner will not be saved in meaningful way.

So in short, root ownership will be preserved if tarball'd or copied via extX usbstick or the like. Non-root ownership is unreliable.

Related Question