Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Detailed explanation of chmod command

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/03 Report--

chmod is used to change access to files or directories. It is used by users to control access to files or directories. This command has two uses. One is a literal setter that contains letters and operator expressions; the other is a numeric setter that contains numbers.

1. French: chmod [who] [+]| - |=] [mode] The options in the file name command mean: The operand who can be any one or a combination of the following letters: u stands for "user," that is, the owner of the file or directory. g stands for "group users," i.e. all users with the same group ID as the file owner. o stands for "others." a stands for "all users." It is the system default. The action symbol can be: + Add a permission. - Revoke a privilege. = Grant the given permission and revoke all other permissions, if any. The permissions indicated by setting mode can be any combination of the following letters: r readable. W can be written. x Executable. X Append the x attribute only if the target file is executable for some users or if the target file is a directory. s sets the process owner or group ID to the file owner of the file when the file executes. The mode "u+s" sets the user ID bit of the file, and "g+s" sets the group ID bit. tSave the text of the program to the switching device. u has the same permissions as the file owner. g Has the same permissions as users in the same group as the file owner. o Have the same privileges as other users. File Name: A list of files to change permissions separated by spaces. Wildcards are supported. Multiple permission modes can be given on a command line, separated by commas. For example: chmod g+r, o+r example % Gives the group and other users read access to the file example. 2. We must first understand the meaning of attributes represented by numbers: 0 means no permission, 1 means executable permission, 2 means writable permission, 4 means readable permission, and then add them. So the numeric attribute should be in the form of three octal numbers from 0 to 7, in the order (u)(g)(o). For example, if you want the owner of a file to have read/write permissions, you need 4 (readable)+2 (writable)=6 (read/write). The general form of the numerical setting method is: Syntax: chmod [mode] File name command Example: chmod a+x sort % That is, the attributes of the file sort are set as: File owner (u) Increase execution permissions and file owner Group user (g) Increase execution permissions Other users (o) Increase execution permissions chmod ug+w, o-x text% That is, the attributes of the file text are set as: File owner (u) Increase write permissions User in the same group as file owner (g) Increase write permissions Other users (o) Delete execution permissions chmod u+s a.out% Assuming that the permissions of a.out after executing chmod are (can be seen with ls - l a.out command): -rws-x-x 1 inin users 7192 Nov 4 14:22 a.out And this execution file uses a text file shiyan1.c, whose file access permissions are "-rw---," that is, only its owner has read and write permissions. When another user executes a.out, his identity is temporarily changed to inin (due to the use of the s option in the chmod command), so he can read the file shiyan1.c (although this file is set so that no one else has any permissions), which is the function of s. Therefore, in the whole system, especially the root itself, it is best not to set up too many files of this type (unless necessary) so as to ensure the security of the system and avoid the system being damaged due to bugs in some programs. chmod a-x mm. txtchmod -x mm. txtchmod ugo-x mm. txt% These three commands delete the execution permission of the file mm.txt, and the object it sets is all users.$ chmod 644 mm.txt % is to set the attributes of the file mm.txt as: -rw-r-r-file owner (u) inin has read and write permissions with the file owner group user (g) has read permissions others (o) have read permissions chmod 750 wch.txt% is to set wchtxt The attributes of this file are: -rwxr-x-file owner (u) inin readable/writable/executable rights group with file owner (g) readable/executable rights others (o) no rights

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report