What is the main difference between chmod and chown?

DaRecordon

Well-known member
Joined
Oct 7, 2016
Messages
138
Best answers
0
Ratings
5
Points
18
#1
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?
 
Joined
May 9, 2018
Messages
17
Best answers
0
Ratings
13 6
Points
3
#2
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
Joined
Oct 7, 2016
Messages
138
Best answers
0
Ratings
5
Points
18
#4
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
202
Replies
5
Views
306
Replies
19
Views
506
Replies
0
Views
184
Replies
0
Views
191
Recommended Threads
Replies
2
Views
718
Replies
6
Views
1,669
Replies
6
Views
1,719

Latest Hosting OffersNew Reviews

Sponsors

Latest Blog ArticlesMost Viewed Threads

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