In my Linux, there was originally a centos user, and there was a centos folder under the/home directory.
1. useradd fit001 is used to create a new user (when a new user is created, if no user group is specified, a user group with the same name is created by default );
2. Use passwd fit001 to set a password for the newly created user;
3. view the/home directory and add a fit001 folder.
The owner of the centos folder in the/home directory is rwx ------ for the centos file, and the owner of the fit001 folder is rwx ------ for the centos file ------.
Log on to the system using SSH as the root user and run the CP-RF/home/centos/desktop/home/fit001 command to copy the Desktop Folder in the centos folder to the fit001 folder.
Use SSH to log on to the system as a fit001 user and run the CP-RF/home/centos/desktop/home/fit001 command to copy the Desktop Folder in the centos folder to the fit001 folder without permission, copy failed.
When you log on as a root user, you can use the CD command to go to The centos folder and view the Desktop Folder. fit001 users cannot log on to the centos folder and do not have the permission to use CD.
To verify the permission, the root user uses chmod 770/home/centos to change the centos permission to rwxrwx ---, And the fit001 user cannot log on to the centos folder.
After you change the permission of the centos folder to rwx --- rwx, you can log on to the centos folder as a fit001 user.
This experiment aims to verify the relationship between file permissions and users and user groups.
First, the file has four permissions: read, write, execute, and no permission;
Objects can have different types of permissions for three different types of users: file owner, and users in the same group as owner (groups) other users (others, neither the owner nor the users in the same group as the owner), the file permission order is owner groups others
The four permissions of a file are represented by characters: R, W, X, and-in decimal numbers, which are 4, 2, 1, and 0.
The four permissions have different meanings on files and directories:
Common file directory
R: You have the permission to read the file content. You have the permission to list the file list.
W: You have the permission to modify the file content. You have the permission to create and delete files.
X: the user has the permission to execute the file. The user has the permission to access the Directory and copy the file.
If you have a certain permission, you may not be able to perform operations on files or directories. Here is my experiment:
Directory permission:
1) the root user creates the folder test under/OPT, and chmod 000/opt/test does not give any permission to the directory. Under the root user, you can enter the test folder and list the content in the folder.
When you Log On As A centos user, you cannot use the CD command to enter the test directory.
2) Log On As the root user chmod 004 test and as the centos user. The CD test cannot enter the directory or use the LS command to list the content in the folder.
3) Log On As the root user chmod 002 test and as the centos user. CD test cannot enter the directory, and touch test/test.txt cannot create files.
3) Log On As the root user chmod 006 test and as the centos user. CD test cannot enter the directory, list the content in the folder, and create files in the folder.
4) Log On As the root user chmod 001 test and as the centos user. The CD test can enter the directory, and the contents in the folder cannot be listed and files cannot be created.
5) chmod 005: You can enter the folder and list the content in the folder, but you cannot create a file in it.
6) chmod 003: You can enter the folder and create a file, but cannot list the file content.
A non-root user must have the X permission for folder operations. Only the X permission can be used to access folders and perform operations on folders.
File Permission:
1) Create the file test.txt, chmod 000/opt/test.txt under/optas as the root user and do not grant any permissions to the file. The file content cannot be viewed under the root user.
2) In chmod 200/opt/test.txt, the root user cannot view the file content and cannot write data to the file.
3) In chmod 300/opt/test.txt, the root user cannot view the file content and cannot write data to the file.
4) chmod 400/opt/test.txt. the root user can view the file content and write data to the file.
5) in chmod 001/opt/test.txt, centos users cannot view the file content and cannot write data to the file.
6) in chmod 003/opt/test.txt, The centos user cannot write data to the file and cannot view the file content.
7) chmod 004/opt/test.txt. centos users can view the file content and cannot write content to the file.
8) chmod 006/opt/test.txt. centos users can view the file content and write content to the file.
The root user only needs the r permission to read and write files, and the X permission is required for file execution. For non-root users, the r permission is required to write files. If only w permission is required to read files and write content to files, X permission is required to execute files. The r-X file is readable and executable and cannot be written.
Reference: http://linux.chinaitlab.com/administer/814112.html