Linux permission and ownership model (1)

Source: Internet
Author: User

One user and one group
Let's take a look at the Linux permission and ownership model. We can see that each file belongs to a user and a group. This is the core of the permission model in Linux. You can view users and groups in the ls-l list:

$ ls -l /bin/bash-rwxr-xr-x1 root wheel 430540 Dec 23 18:27 /bin/bash
In this special example, the/bin/bash Executable File belongs to the root user and is in the wheel group. The Linux permission model allows three independent permission levels for each file system object-they are the file owner, the file group, and all other users.
Understanding "ls-l"
Let's take a look at our ls-l output and check the first column of this list:
$ Ls-l/bin/bash-rwxr-xr-x1 root wheel 430540 Dec 23/bin/bash the first field-rwxr-xr-x contains a symbolic representation of the permissions for this particular file. Specifies the file type. In this example, it is a regular file. Other possible first characters include:
"D" directory "l" Symbolic Link "c" character dedicated device file "B" block dedicated device file "p" first-in-first-out "s" socket three triplet $ ls-l/ bin/bash-rwxr-xr-x1 root wheel 430540 Dec 23/bin/bash the rest of this field consists of three triple characters. The first three-character group represents the permissions of the file owner, the second represents the permissions of the file group, and the third represents the permissions of all other users:
"Rwx" "r-x" "r-x" above, r indicates that reading and viewing data in the file is allowed), w indicates that writing, modifying, and deleting files are allowed ), x indicates that the program can be run ). Put all this information together, we can find that everyone can read and execute the file, but only allow the file owner root User) can modify the file in any way. Therefore, although you can copy the file, only the root user is allowed to update or delete it.
Who am I? Before learning how to change the user ownership and group ownership of a file, let's first take a look at how to know your current user identity and membership. Unless you have recently used the su command, your current user ID is the user ID you use to log on to the system. However, if you use su frequently, you may not remember your current valid user ID. To view the user ID, enter whoami: # whoamiroot # su drobbins $ whoamidrobbins in which group do I belong? To see which group you belong to, run the group Command $ groupsdrobbins wheel audio. In the preceding example, I am a member of the drobbins, wheel, and audio groups. If you want to see the groups of other users, specify their usernames as parameters:
$ Groups root daemonroot: root bin daemon sys adm disk wheel floppy dialout tape videodaemon: daemon bin adm changes user and group ownership in order to change the owner or group of files or other file system objects, use chown or chgrp respectively. Both commands require one user name or group name as the parameter, followed by one or more file names.
# Chown root/etc/passwd # chgrp wheel/etc/passwd you can also use another form of chown command to set the owner and group at the same time:
# Chown root. wheel/etc/passwd unless you are a super user, you cannot use chown. However, anyone can use chgrp to change the group ownership of files to the group they belong.
Recursive ownership changes both chown and chgrp have a-R option that can be used to recursively apply ownership and group changes to the entire directory tree. For example: # chown-R drobbins/home/drobbins introduction chmodchown and chgrp can be used to change the owner and group of File System Objects, another program called chmod is used to change the rwx permission we can see in the ls-l list. Chmod has two or more parameters: "mode", which describes how to change permissions, followed by the list of files or files that will be affected: $ chmod + x scriptfile. sh in the above example, our "mode" Is + x. As you may guess, the + x mode tells chmod that the special file is executable to users, groups, and anyone else. If we want to remove all the execution permissions for a file, we should do this: $ chmod-x scriptfile. sh user/group/other granularity up to this point, our chmod example has affected all three triplet-users, groups and all other users. Generally, it is convenient to modify only one or two three tuples at a time. To do this, you only need to specify the symbol character for the specific triple that you want to modify before the + or-symbol. Use u for the "user" triple, g for the "Group" triple, and o: $ chmod go-w scriptfile for "Others/everyone. sh we just removed the write permissions of the group and all other users, but kept the "owner" permission unchanged. In addition to opening and disabling permission slots, You can reset the permissions together. By using the = Operator, we can tell chmod that we want to specify the permission and cancel other permissions: $ chmod = rx scriptfile. sh above, we only set all the "read" and "execute" bits, but not all the "write" bits. If you only want to reset a specific triple, you can specify the symbol name of the triple before = as follows:
$ chmod u=rx scriptfile.sh


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.