1. Check the permissions of files and directories

Run the ls command to display only the file name. Run the ls -al command (or ll) with parameters to display the permission information of a file or directory.

Ls -l File name The following information is displayed: File type (d directory, -common file, l link file), file permission, user of the file, owning group of the file, file size, file creation time, and file name, as shown in the following example:

-rw-rw-r-- 2 snzl snzl   23 Aug 21 06:05 1.txt
Copy the code

The above example can be broken down into the following fields:

-rw-rw-r– 1 snzl snzl 23 Aug 21 06:05 1.txt
Document types and permissions The number of connections User of the document Document Group Document size Date the document was last modified The document name

1.1 Document Types and Permissions

For the document type and permission fields, divide them into four groups. The number of characters and meanings of each group are as follows:

  • -: File type: A common file
  • rw-: User permission: indicates the usersnzlHas the read, write, and execute permissions
  • rw-: User group Permission: indicates a user groupsnzlOnly read and write permission, but no executable permission
  • r--: Other user permissions: Other users have read permissions but do not have write or run permissions
rw- rw- r–
The document type Document owner permissions (user) Permission of the user group to which the document belongs (group) Other User rights (other)

The main document types are:

  • dSaid directory
  • lIndicates soft connection
  • -Said file
  • cRepresents a serial port character device file
  • bRepresents a block device file available for storage

The remaining characters are grouped in groups of three. R read-only, w writable, x executable, – indicates no permission

1.2 the number of connections

Refers to how many files point to the same inode.

1.3 Owning User and Group of the Document

Which user and user group the document belongs to. The user and group that a file belongs to can be changed

1.4 Document Size

The default is bytes

2. Change the operation rights

2.1 chmod

Changing access Permissions

  • Chmod [who] [+ | | =] [mode] file name

Figure:

2.2 chown

“Change owner” means to change the owner of a file or directory. The owner includes users and user groups

  • Chown [-r] User name file or directory
  • Chown [-r] User name User group name File or directory

-r: recursively changes the permissions of all files and subdirectories in a directory to the permissions of the specified user group

At this point, the file cannot be modified.

You can make a file modifiable by modifying the owner of the file.

2.3 the who

The operation object can be one or a combination of the following letters

  • U: user user
  • G: user group group
  • O: indicates other users
  • A: Indicates that all users are default

2.4 Operation Symbols

  • + : adds a permission
  • – : cancels a permission
  • = : Grants the given permission to revoke all previous permissions on the document

2.5 mode

The permission can be R, w, or x

2.6 the file name

A list of files whose names can be separated by Spaces

2.7 the sample

root@Ubuntu:~$ ls -al test.txt 
-rw-rw-r-- 1 snzl snzl 6 Aug 21 21:47 test.txt
root@Ubuntu:~$ chmod u=rwx,g+r,o+r test.txt 
root@Ubuntu:~$ ls -al test.txt 
-rwxrw-r-- 1 snzl snzl 6 Aug 21 21:47 test.txt
root@Ubuntu:~$
Copy the code

3. Number setting method

The meaning of a numeric representation in a numeric setting

  • 0 indicates no permission
  • 1 indicates the executable permission =x
  • 2 indicates the write permission =w
  • 4 indicates the readable permission =r

Permissions can also be represented by numbers such as chmod 755 file\_name

r w x R – x r – x
4 2 1 4-1 4-1
user group others
  • For the RWX attribute 4+2+1=7
  • For the RW – attribute, 4+2=6
  • For r-x attributes, 4+1=5
root@Ubuntu:~$ chmod 777 test.txt 
root@Ubuntu:~$ ls -al test.txt 
-rwxrwxrwx 1 snzl snzl 6 Aug 21 21:47 test.txt

root@Ubuntu:~$ chmod 770 test.txt 
root@Ubuntu:~$ ls -al test.txt 
-rwxrwx--- 1 snzl snzl 6 Aug 21 21:47 test.txt
Copy the code

The above.