- Joined
- Oct 7, 2016
- Messages
- 247
- Points
- 18
Can you tell me what is the main difference between chmod and chown? I am confusing to distinguish how chmod and chown work and when I need to use chmod or chown on my hosting server. Any explanations?
I understood after read 2 these lineschmod is used for changing the permission - what level of access a particular entity has to that file.
chown is used to change ownership information of a file - what user and group has access to the file.
For example, on a typical cPanel server and a lot of other web servers, Apache will run as the user nobody and the group nobody. This means any file owned by the nobody user, Apache will have access to. Any file whose group is set to nobody, Apache will also have access to. What level of access? Well, that's determined by the permissions of the file - which you set with chmod.
Typically we see HTML files owned by the account's user and that account's group, i.e. user:user. Typically we see files set with a permission setting of 644 (rw-r--r- - or User: read and write / Group: read / Other: read). The other bit defines what level of access everyone else has on the file - user's that aren't the file's owner, and users who are in groups that are not in the file's group.
In this sense, HTML files need to be set at 644 so that Apache (the user nobody) can read the file. Because the file is owned by the user and the user's group, there is no nobody access to the file, so this access level falls under the Other bit, which has read access.
If the file was owned by user but by the group nobody (i.e. user:nobody) then permissions of 640 (rw-r----- or User: read and write / Group: read / Other: none) would be sufficient. This is because Apache is running under the group nobody and the group bit for this file is set to read and the group ownership of this file is set to nobody.
If the file is owned by user:user and set with a permission of 640, then the Apache user (user nobody) no longer has sufficient privileges to read the file, and thus won't be web viewable.
Just one more question, chmod can be used for all groups to access files/folders while chown is limited to any groups that it allows? and I can allow the second user for chown command? as you mentioned to user:user in its command. I mean I can have more than one group fro chown?chmod is used for changing the permission - what level of access a particular entity has to that file.
chown is used to change ownership information of a file - what user and group has access to the file.