Chmod (File Permissions) in *nix System Explained
File Permissions plays important role in *nix OS, if you are a webmaster then you must have faced some situations when due to file permissions your web applications wont behave as per excepted or some time it shows 500 error or sometime it makes your script not able to read/write a file. You must have solved these sort of problems by applying chmod 777 or chmod 750 commands , and your script starts working. But for the curious users who wants to know that what happens in behind the scene this article will explain all those things.
File Permissions are the roles which defines that who (user,group,world) can do what (read, write, execute ) operations on that file or directory.
There are 3 entity which needs to deal with file, these are -
- User (root,vivex,www-data,apache etc)
- Group (each user is associated with a group)
- Others (all other world)
And there is 3 permissions
- Read (weight 4)
- Write (weight 2)
- Execute (weight 1)
these weight makes the digits 755 and all , how?
Suppose if we want that user can read a file and group and others with no permission then for user (read = 4) so just chmod file to 400 -
User Group Other
4 0 0
for read and write – 4+2 = 6 , for read+write+execute – 4+2+1 = 7
Same apply for directories if a directory have only write permission then it makes no sense since you cant read the content, you can even execute ls in that directory, Neither you can enter into it. Only executing permission to directory also make no sense, you can do only cd and enter into the directory but you cant read nor write files in that directory, so for user you have to give all three permission to that directory.