Detailed description of user group and file permissions in Linux

Source: Internet
Author: User

Detailed description of user group and file permissions in Linux

User Group

In Linux, each user must belong to a group and cannot be independent from other users. In Linux, each file has the concept of owner, group, and other groups.

-Owner
-Group
-Other Groups
-Change the user's group

Owner

Generally, it is the creator of a file. Whoever creates the file naturally becomes the owner of the file.
Run the ls-ahl command to view the file owner.
You can also use the chown user name and file name to modify the file owner.

File Group

After a user creates a file, the file group is the user group.

Run the ls-ahl command to view all groups of the file.

You can also use the chgrp group name to modify the group in which the file is located.

Other groups

In addition to the owner of the file and the owner of the group, other users of the system are all other groups of files.

File Permission

Ls

-L:

-Rwxrw-r‐- 1 root 1213 Feb 2 abc

-10 characters to determine what different users can do with files

-The first character represents the file (-), directory (d), and link (l)

-The remaining characters are in a group of three (rwx), read (r), write (w), and execute (x)

-Group 1 rwx: the permissions of the file owner are read, write, and execute.

-Group 2 rw-: the permissions of users in the same group as the file owner are read, write, but cannot be executed.

-Group 3 r --: other users in the same group as the file owner are not allowed to write or execute the read

It can also be expressed as follows: r = 4, w = 2, x = 1, so rwx = 4 + 2 + 1 = 7

-1 indicates the number of connected files

-Root indicates the user

-Root indicates the user's group.

-1213 indicates the file size (in bytes)

-Feb 2 indicates the last modification date

-Abc indicates the file name.

Command for permission change

Chmod changes the permissions of files or directories

Chmod 755 abc: grant the abc permission rwxr-xr-x

Chmod u = rwx, g = rx, o = rx abc: Same as u = user permission, g = Group permission, o = other user permissions of different groups

Chmod u-x, g + w abc: removes the user's execution permission for abc and adds the group write permission.

Chmod a + r abc: Read Permission for all users

Change the owner (chown) and user group (chgrp) commands

Chown xiaoming abc: Change the abc owner to xiaoming

Chgrp root abc: Change the abc Group to root.

Chown root./abc: Change the owner of the abc directory to root.

Chown-R root./abc: the owner of the abc directory and all files and directories under it is root.

 

Change User Group

When adding a user, you can specify the group to which the user is added. You can also change the group of a user with the root management permission.

-Usermod-g group name Username

You can use

-Usermod-d directory name Username: Change the user's initial logon directory

[Comprehensive case]

[Question 1.1] create two user groups: group1 and group2, and assign the first two users to the group1 user group, and then assign the last two users to the group2 user group.

[Question 1.2] Log On As A dennis user and create a Hello. java File

[Question 1.3] Log On As A daniel and check whether the/home/dennis directory can be accessed and whether the Hello. java File Created by daniel can be read or written.

[Question 1.4] Log On As A dennis user and modify the/home/dennis and Hello directories. java file read and write permissions (correct: when modifying the directory permission, 770 should be used instead of 760; otherwise, the permission is insufficient)

[Question 1.5] Repeat [question 1.3]

[Question 1.6] changing the user group of abigale from group2 to group1

Then, you can use cat/etc/passwd to view and confirm

[Reference]

-Groupadd group name: Add group name in linux

-Vi/etc/group: View All group information in linux. You can edit it.

-Cat/etc/group: displays information about all groups in linux.

-Useradd‐g indicates the group name username. When creating a user, specify the group to which the user is assigned.

-Vi/etc/passwd: view all user information in linux. You can edit it.

-Cat/etc/passwd: view all the user information in linux.

Linux permission supplement: rwt rwT rws rwS special permissions

Linux User and User Group Permissions

Three special Linux permissions: setuid setgid stick bit

Getting started with Linux: A Brief Description of Linux File Permissions

This article permanently updates the link address:

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.