How can users be granted file permissions in Linux?
In Linux, you can use the chmod command to grant file permissions to users. The basic syntax of the chmod command is as follows:
Modify the mode of permissions for a file by using the command “chmod” followed by the desired options, permission mode, and file name.
“Do you have any preferences?”
- -c: Display detailed information about permission changes.
- – R: Recursively change the permissions of folders, files, and subfolders within them.
The permission mode is made up of three numbers, representing the permissions of the file owner, the file’s group, and other users. Each number consists of three binary digits, representing the read (r), write (w), and execute (x) permissions. Specifically, r is 4, w is 2, x is 1, and no permission is 0. For example, rwx permission is represented as 7, rw- permission is represented as 6, r– permission is represented as 4, and so on.
Here are some common examples:
Grant the file owner the permission to read, write, and execute.
chmod u+rwx 文件名
Grant read and execute permissions to the file’s group.
chmod g+rx 文件名
Grant execution permission to other users.
chmod o+x 文件名
Grant read and execute permissions to both the file owner and the group simultaneously.
chmod ug+rx 文件名
Grant read permissions to all users.
chmod a+r 文件名
Grant full permission to the owner and group of the file, while denying access to other users.
chmod ug+rwx 文件名
The above are just some basic examples. You can combine and adjust permission modes according to specific needs.