Linux and Unix are multi-user operating systems, so the implementation of file permissions and ownership is very necessary; each file mainly deals with three sets of permissions, namely user, group, and other users. User (u) is the owner of the file and usually has all file operation permissions A user group (g) is a collection of multiple users, which may have partial access rights to files, equivalent to sharing files between users. Other (o) refers to anyone other than the file owner and group members. Use ls -l to display various information including file type, permissions, owner, and group in the current directory; The first column means: -(filetype)---(user)---(group)---(other), each group of permissions corresponds to a three-digit binary number, the first bit indicates read (r) permission, the second bit indicates write (w) permission, and the third bit indicates execute (x) permission (if the file is executable); when the corresponding permission is obtained, the corresponding bit is set to 1 (otherwise 0), indicating that the current object has this permission 1: User can read, write and execute: -rwx------. Generally speaking, for data files, the user's permission is rw-, and the permission of executable files and scripts is rwx. For users, there is also a special permission called setuid, which can appear in the position of permission x. The setuid (S) permission allows the executable file to be executed with the permissions of its owner, even if the executable file is run by other users. If the permission is granted, the sequence is: -rwS------ 2: User group read, write and executable: ----rwx---, For the user group, it has a special permission called setgid(S) which allows us to use any valid user group to run the file, provided that the group needs to have the same permissions as the file's required group,, ----rwS--- 3: Other users: -------rwx 1: Use chmod (change mode) to set file permissions: --x=1;-w-=2;r--=4; rx=5;rw-=6;rwx=7; If you set permissions: rwxrw-r-- 1:chomd 764 filepath 2:chmod u=rwx, g=rw, o=r filepath; chmod ugo=r, g=w filepath To add or remove permissions for a file: 1: Add executable permissions to users and user groups (+): chmod u+x, g+x filepath 2: Delete (-) the executable permissions of the user group: chmod g=ur filepath means to set the permissions of the user group to the same permissions as the user, but delete the r permission 3: Add/remove executable permissions for all permission categories (a) (i.e. user, user group, other users) chmod a+x filepath 2. Change Ownership 1: Use chown to change the ownership of a file. Ordinary users do not have the authority to change the owner of other people's files, nor do they have the authority to change the owner of their own files to someone else. Only the system administrator (root) has such authority: chown user:group filepath (user, group is the new user and user group) 2: Set the sticky bit for the directory Sticky bit: Directories have a special permission called the sticky bit. If the sticky bit is set for a directory, only the user who created the directory can delete files in the directory. It appears in place of the execute permissions for the Other User Group. When the execution permission is set -------rwt, when the execution permission is not set -------rwT, chmod a+t dirname 3: Set ownership and file permissions recursively, using option -R; Supplement: File type: - ordinary file d directory (directory); c character device (char); b block device (block); l symbolic link (link); s socket (socket); p pipe (pipe) Summarize The above is the editor’s introduction to modifying file permissions under Linux. I hope it will be helpful to everyone! You may also be interested in:
|
<<: Detailed explanation of MySQL covering index
>>: Vue+js click arrow to switch pictures
There are many differences between IE6 and IE7 in ...
In this article we assume you already know the ba...
As a backend programmer, you deal with Linux in m...
This article uses examples to illustrate the prin...
Rendering If you want to achieve the effect shown...
Table of contents 1. Current situation 2. Create ...
This article shares the specific code of JavaScri...
This article shares the specific code of js to ac...
1. Before configuring the IP address, first use i...
The growth path from a Linux novice to a Linux ma...
1. Slow query log 1.1 MySQL log types Logs are us...
In real life, a lock is a tool we use when we wan...
Tab switching is also a common technology in proj...
Download MySQL for Mac: https://downloads.mysql.c...
1. What are custom hooks Logic reuse Simply put, ...