User groups, file permissions in Linux under the detailed

Source: Internet
Author: User
Tags file permissions

Each user in Linux must belong to a group and cannot be independent of the group. Each file in Linux has the concept of owner, group, other group

-Owner

-Group

-Other groups

-Change the group where the user is located

Owner

Typically the creator of the file, who created the file, becomes the owner of the file naturally

You can see the owner of the file with the Ls‐ahl command

You can also use the Chown user name file name to modify the file owner

The group where the files are

When a user creates a file, the group where the file is located is the group that the user is in

All groups of files can be seen with the Ls‐ahl command

You can also use the CHGRP group name file name to modify the group in which the file resides

Other groups

Other users of the system are other groups of files, except for the owner of the file and the user in the same group

File permissions

Ls

The contents shown in-L are as follows:

-rwxrw-r‐-1 root root 1213 Feb 2 09:39 ABC

-10 characters to determine what different users can do with a file

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

-The remaining characters are set per 3 (RWX), read (R), write (W), execute (x)

-First set of rwx: The file owner's permissions are read, write, and execute

-Second group rw-: Permissions for users of the same group as the file owner are read, write, but cannot be executed

-Third group r--: the permissions of other users who are not in the same group as the file owner are read and cannot be written and executed

Also available as a number: R=4,w=2,x=1 so rwx=4+2+1=7

-1 indicates the number of files connected

-Root indicates that the user

-Root indicates the group to which the user resides

-1213 indicates file size (bytes)

-Feb 2 09:39 indicates last modified date

-ABC indicates file name

Commands to change permissions

chmod changing the permissions of a file or directory

chmod 755 ABC: Give ABC permission rwxr-xr-x

chmod U=RWX,G=RX,O=RX ABC: ibid. u= User Rights, g= group permissions, o= different groups of other user rights

chmod u-x,g+w ABC: for ABC to remove user-executed permissions, increase group Write permissions

chmod a+r ABC: Add read permissions to all users

Change owner (chown) and user Group (CHGRP) commands

Chown xiaoming ABC: Change the owner of ABC to Xiaoming

CHGRP Root ABC: Change the group that the ABC belongs to IS root

Chown root./ABC: Change ABC the owner of this directory is root

Chown‐r root./ABC: Change the ABC directory and the owner of all files and directories below it is root

Change the user group

When you add a user, you can specify which group to add the user to, as well as root administrative permissions to change the group in which a user resides

-USERMOD‐G Group name User name

You can use

-Usermod‐d directory name User name, change the initial directory of the user login

"Comprehensive Case"

"Question 1.1" establishes two user groups Group1 and group2, and three users Dennis, Daniel, Abigale, and assigns the first 2 users under the Group1 user group, and the latter is assigned under the GROUP2 user group

"Question 1.2" to Dennis User login, create a Hello.java file

Question 1.3 Logs in with a Daniel user to see if you can access the/home/dennis directory and read or write the Hello.java file it created

"Question 1.4" to Dennis User login, modify the directory/home/dennis and Hello.java file read and Write permissions (correct: Modify directory permissions, should use 770, not 760, otherwise insufficient permissions)

Question 1.5 "Repeating" question 1.3 "

"Question 1.6" change Abigale user group from group2 to Group1

You can then use CAT/ETC/PASSWD to view and determine

Reference

-Groupadd group name, adding groups to Linux

-Vi/etc/group, see all the group information in Linux, can be edited

-Cat/etc/group, view all the group information in Linux, can not be edited

-USERADD‐G group name User name, create a user and specify which group to assign the user to

-VI/ETC/PASSWD, see all user information in Linux, can be edited

-CAT/ETC/PASSWD, view all the user information in Linux, can only see can not edit

User groups, file permissions in Linux under the detailed

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.