What is the main difference between chmod and chown?

DaRecordon

Well-known member
Registered
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?
 

BenZ-AMS

Member
Registered
Joined
May 9, 2018
Messages
22
Points
3
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.

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.
 

DaRecordon

Well-known member
Registered
Joined
Oct 7, 2016
Messages
247
Points
18
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.
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.
I understood after read 2 these lines

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.
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?
 
Older Threads
Replies
1
Views
1,786
Replies
5
Views
2,059
Replies
19
Views
5,838
Replies
0
Views
1,320
Replies
0
Views
1,311
Latest Threads
Replies
0
Views
122
Replies
0
Views
65
Replies
0
Views
58
Replies
1
Views
87
Recommended Threads
Replies
12
Views
4,402
Replies
6
Views
4,887
Replies
4
Views
1,549
Replies
20
Views
7,414

Latest postsNew threads

Latest Hosting OffersNew Reviews

Sponsors

Tag Cloud

You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an alternative browser.

Top