i don't know the reason why but Linux user permissions is not working on NTFS file system... anyway, if a file was copied from windows to Ubuntu, Ubuntu has to give them an ownership and a user permission as well.. so where does Ubuntu save user permission of a file? the thing is, moving a file from Linux distro to another doesn't change permissions. so it should be inside of the file for sure. does Ubuntu rewrite each and every file?
Linux uses NTFS via software called NTFS3G (google for details if interested). Linux and NTFS have totally different concepts of users, groups and file permissions. This means it's not simple to translate permissions between systems.
To adjust NTFS permissions into Linux form NTFS3G has 2 possibilities: (a) just ignore what NTFS has and set all files and all directories to the same umasks; or (b) provided that user mapping was done, it attempts to guess what meaning of Linux permission are resulted from NTFS permissions of a paricular file/dir.
In case (a) Linux-supplied permissions are not stored anywhere and any attempts to change them are ignored. Case (b) reads and stores file permissions in NTFS.
ext filesystem, which is used in Linux, inodes are used to describe stored files. An inode contains attributes of a file as well as its data block locations (these are the blocks that contain the actual contents of the file). The following is briefly what is stored in an inode:
Inode number File access, modify and changed timestamps File size Permissions Owner Group Data Block Locations
So to answer your question, Unix stores the permissions of a file in its inode, which is in the filesystem, for example
If you want to see the inode information of a file, you can use the
$ stat /bin/bash File: ‘/bin/bash’ Size: 635933 Blocks: 624 IO Block: 65536 regular file Device: 2e208854h/773883988d Inode: 281474976901122 Links: 1 Access: (0755/-rwxr-xr-x) Uid: ( 1000/ Alaa) Gid: ( 513/ None) Access: 2014-10-18 13:45:13.375853300 -0400 Modify: 2014-10-08 16:54:16.000000000 -0400 Change: 2014-10-18 13:45:13.438253400 -0400 Birth: 2014-10-18 13:45:13.375853300 -0400
To point out something in your question: by default, when you copy a file from a Linux distribution to another, the permissions are not copied. What happens is that the data blocks (the actual contents) are copied, but all the other attributes are not. So for example, if you are copying files from your internal to your external hard drive (both formatted as
ext4), the owner of the copied data on the external hard drive becomes (I think) the user that did the copy command. If you wanted to preserve the permissions (and other attributes) of a file, you would have to use an extra flag, such as
--preserve) in the
-p same as --preserve=mode,ownership,timestamps --preserve[=ATTR_LIST] preserve the specified attributes (default: mode,owner- ship,timestamps), if possible additional attributes: context, links, xattr, all
mode is the permissions. Using options like the
-p copies over those inode attributes to the new file.
Windows uses the FAT32 or NTFS which are completely different filesystems that don't understand inodes. That's why, when you copy something from Linux (
ext4) into Windows (NTFS or FAT32), Windows applies its own attributes to the file.
When you mount an NTFS filesystem in Ubuntu, it sets permissions on everything in the partition using the
umask command (or options
fstab). When you copy something over to that mounted partition, those files take whatever the
umask command entails, and the permissions cannot be changed unless you remount the whole partition with new options.
For more information, read the manpage of ntfs-3g here: http://linux.die.net/man/8/ntfs-3g.