The chown command is used to change the file's user or group owner for each file. The chmod command changes file access permissions (read/write/execute).
chown command
Here's how you would assign user/group association with a directory:
# chown root:root /var
- Note* Keep in mind that the first root you're associating belongs to user and the second 'root' belongs to group.
Here's how you would assign user/group association with a file:
# chown root:groupname /home/upload/filename.txt
chmod command
There are two separate groups (role & permission) that dictate how a file will be owned and how it can be handled. Each group has 3 different assignments that can be customized to how you see fit. Below you'll find the groups and each groups assignments:
Roles
- u stands for user
- g stands for group
- o stands for others
Permissions
- r stands for read permission
- w stands for write permission
- x stands for execute permission
Now that you understand what the roles and permissions are, let's put them to use.
Here are some example commands to perform basic role/permission association:
Add a single permission to a file/directory
The + symbol adds a single permission. Here's an example of utilizing +:
# chmod u+x filename
You have associated that file with the user and also added the execute permission to that file. In the following commands you will find + utilized often, to get you used to using that extension.
Add multiple permission to a file/directory
# chmod u+r,g+x filename
- Note* The comma separates the multiple permission sets.
Remove permission from a file/directory
The following example removes read and write permission for the user.
# chmod u-rx filename
Change permission for all roles on a file/directory
Following example assigns execute privilege to user, group and others. a equals 'all'.
# chmod a+x filename
Make permission for a file same as another file (using reference)
If you want to change a file permission same as another file, you'll need to use the reference option as shown below. In this example, file2 permission will be set exactly same as file1 permission.
# chmod --reference=file1 file2
Change execute permission only on the directories (files are not affected)
If you want to only set permissions to directories/sub-directories and not affect the files stored in them, you can set this up by following the example command below:
# chmod u+X *
- Note* If the files has execute permission already for either the group or others, the above command will assign the execute permission to the user
ليست هناك تعليقات:
إرسال تعليق