Linux basics-in-depth discussion of Unit 7 users, groups, and permissions

Source: Internet
Author: User

Linux basics-in-depth discussion of Unit 7 users, groups, and permissions

How to View File Permissions
Ls command details
Root User and file security control
What is a root user?
User category
File Operation permission
Character representation of file operation Permissions
Chown
Chgrp
Use symbolic notation to set permissions on files or directories
Functions of the chmod command
-R option of the chmod command
What is symbolic notation
Three parts of the permission status
Symbol notation example
Use numeric notation to set permissions on files or directories
What is digital notation
Number indicates the resource permission status
Digital representation example


Homework
[Content of this section]
1. How to View File permissions (see linux P138)
1) Use the ls-l command to view the permissions set on the file.
2) The first column in the display result of the ls-l command is divided into four groups;
A) a 1st character group contains 1st characters, which indicates a file (-), a directory (d), or other resources.
B) the 2nd, 3, and 4 characters are in the 2nd group. The owner of a file or directory has limited permissions, and u is used to represent the owner) all permissions on files.
C. The group contains 5th, 6, and 7 characters, which defines the permissions of other users in the group where the owner of a file or directory is located, use g to represent the group permissions.
D. The group contains 8th, 9, and 10 characters, which Defines permissions for files or directories that are neither the owner nor the owner in the same group. Use o to represent the permissions of this group (other.

3) master the owner and group of the third and fourth columns in the result of ls-l command display.


2. root User and file security control (For details, refer to linux System Management P136)
1) grasp the definition of a root user: A root user, also known as a Super User, can completely access any user's account and all files and directories without restrictions.
2) understand the user categories in Linux:
In Linux, all users in the system are divided into three categories:
A) 1st Class: Owner
B) 2nd class: same group of users (Correction: group, because you will create a group with the same name as the username when creating a user)
C) 3rd category: Non-group users
3) file operation permissions include read, write, and execute)
4) when you have mastered the display permission of the Linux operating system, use the following four characters to indicate the file operation permission:
A) r: indicates the read permission, that is, the permission to read files or list directories by using the ls command.
B) w: indicates the write permission, that is, the permission to edit files or create and delete files in a directory.
C) x: indicates the execute permission, that is, the permission to execute a program, use the cd command to switch to this directory, and use the ls command with the-l option to list details in this directory.
D)-: indicates that no permission is granted (corresponding to the r, w, or x of the location ).


3. Master the file owner using chown
Chown owner: group file
Chown: group file
Chown main file
A) For example, run the chown root file1 command to change the file file1 owner to root.


4. Master the group for modifying files using chgrp
Chgrp group file
A) For example, run the following command to change the file1 group to wg: chgrp wg file1.


5. Use the symbol method to set permissions on files or directories (for details, see linux P132)
1) master the functions of the chmod command: set or change permissions on files or directories.
2) grasp the-R option: not only set (or change) the directory permission, but also recursively set (OR) to change the permissions of all files or subdirectories in the directory.
3) grasp the definition of symbolic Notation:
Symbol notation uses several specific symbols to set the permission status.
4) The permission status can be divided into three parts:
A) Part 1 indicates who wants to set or change the permission status. The specific descriptions are as follows:
U: indicates the owner's permissions.
G: indicates the group permission.
O: indicates the permissions of other users (other) in the same group as the owner.
A: indicates the permissions of the above three groups, that is, all users.
B) Part 1 is an operator, also known as an operator. The specific expression is as follows:
+: Indicates the permission to be added.
-: Indicates removing permissions.
=: Sets permissions.
C) Part 1: permission (permission). The specific descriptions are as follows:
R: read permission.
W: write permission.
X: execut (execution) permission.
5) flexibly apply symbolic notation to set or change permissions on files or directories:
A) For example, add the executable permissions of the owner and the same group of users to the dog_wolf file:
Chmod ug + x dog_wolf
B) For example, the following command adds write permissions to other users in the babydog directory:
Chmod o + w babydog


6. Use digital notation to set permissions on files or directories (see linux P143 for details)
1) understand the definition of digital Notation:
Numeric notation refers to a set of three-digit numbers to indicate the permission status on a file or directory. Where:
1st digits represent the owner's permissions (u ).
The third digit represents the group permission (g ).
The third digit represents the permissions of other users (other) (o ).
2) The number indicates the resource permission status:
4: read permission.
2: write permission.
1: execute permission.
0: no corresponding permissions.
3) flexibly apply numeric notation to set or change permissions on files or directories:
A) For example, you can open the/home/dog/babydog directory and all the files in the directory to the owner in digital notation, but you can open the read and execute permissions to users in the same group, commands that only allow read permission to other users:
Chmod-R 754/home/dog/babydog

 

7. Homework (60 minutes)

1) Create the directory test in the user's home directory and enter test to create an empty file file1

[Root @ study ~] # Cd/home/nulige/

[Root @ study nulige] # mkdir test
[Root @ study nulige] # cd test/
[Root @ study test] # touch file1.

 

2) display the file information in long format. Pay attention to the permissions and users and groups of the file.

[Root @ study test] # ls-l file1
-Rw-r -- 1 root 0 November 10 23:23 file1

 

3) Set permissions for file file1 so that other users can write the file.

[Root @ study test] # chmod o + w file1
[Root @ study test] # ls-l file1
-Rw-r -- rw-1 root 0 November 10 23:23 file1

# Switching users

[Root @ study ~] # Su-huzhihua

[Huzhihua @ study ~] $ Cd/home/nulige/test/
[Huzhihua @ study test] $ ll
Total usage 4
-Rw-r -- rw-1 root 5 November 10 23:33 file1

# Write point content to the file

[Huzhihua @ study test] $ echo 1111> file1

4) view the setting result,

[Huzhihua @ study test] $ cat file1
1111


5) cancel the permission of users in the same group to read file1 and view the setting result.

[Root @ study test] # ls-l file1
-Rw-r -- rw-1 root 5 November 10 23:33 file1

[Root @ study test] # chmod g-r file1
[Root @ study test] # ls-l file1
-Rw ---- rw-1 root 5 November 10 23:33 file1


6) set the permission for the file in digital notation. The owner can read, write, and execute the file. The owner and other users in the group can only read and execute the file. After the setting is complete, view the setting result.

[Root @ study test] # chmod 755 file1
[Root @ study test] # ls-l file1
-Rwxr-xr-x 1 root 5 November 10 23:33 file1


7) change the file1 permission in number format so that the owner can only read the file. No other user has permission. View the setting result.

[Root @ study test] # chmod 400 file1
[Root @ study test] # ls-l file1
-R -------- 1 root 5 November 10 23:33 file1

 

8) return to the upper-level directory to view test permissions.

[Root @ study test] # cd ..

[Root @ study nulige] # ll
Total usage 8
Drwxr-xr-x 2 root 4096 November 10 23:23 test


9) add write permission for this directory to other users

[Root @ study nulige] # chmod o + w test
[Root @ study nulige] # ll
Total usage 8
Drwxr-xrwx 2 root 4096 November 10 23:23 test

 

# Switch other users and write files for testing

[Root @ study ~] # Su-huzhihua
[Huzhihua @ study ~] $ Cd/home/nulige/test/
[Huzhihua @ study test] $ touch test01.txt
[Huzhihua @ study test] $ ll
Total usage 4
-R -------- 1 root 5 November 10 23:33 file1
-Rw-r -- 1 huzhihua 0 November 11 00:02 test01.txt

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.