In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-07 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains the "linux modify authority command is what", the article explains the content is simple and clear, easy to learn and understand, the following please follow the editor's train of thought slowly in depth, together to study and learn "linux modify authority command is what" it!
Linux permission command: 1, chgrp command, used to modify the file and directory belongs to the group; 2, chown command, used to modify the file and directory owner and group; 3, chmod command, can modify the file or directory permissions; 4, umask command, you can make new files and directories have default permissions.
The operating environment of this tutorial: CentOS 6 system, Dell G3 computer.
Linux chgrp command: modify the group to which files and directories belong
The chgrp command is used to modify the group to which a file (or directory) belongs.
To facilitate beginners' memory, chgrp can be understood as an abbreviation for "change group".
The use of the chgrp command is simple, and its basic format is:
Group file name (directory name) to which [root@localhost ~] # chgrp [- R] belongs
The-R (note uppercase) option has a long effect on the group that changes the group of the directory, indicating that the group information of all files in the same subdirectory is changed.
One thing to note when using this command is that the group name to be changed must be real, otherwise the command will not be executed correctly and will prompt "invaild group name".
For example, when you log in to the Linux system as root, there is a file called install.log in the home directory, and we can modify the group of this file using the following methods:
[root@localhost ~] # groupadd group1# create a new group for testing group1 [root@localhost ~] # chgrp group1 install.log# modify the group of the install.log file to group1 [root@localhost ~] # ll install.log-rw-r--r--. 1 root group1 78495 Nov 17 05:54 install.log# modification takes effect [root@localhost ~] # chgrp testgroup install.logchgrp: invaild group name 'testgroup'
You can see that under the premise of having a group1 group, we successfully modified the group to which the install.log file belongs, but when we tried to change the group to testgroup again, the command execution failed because there was no testgroup group in the / etc/group file of the system.
Linux chown command: modify the owner and group of files and directories
The chown command, which can be thought of as an abbreviation for "change owner", is mainly used to modify the owner of the file (or directory). In addition, this command can also modify the group to which the file (or directory) belongs.
When you only need to change the owner, you can use the basic format of the following chown command:
[root@localhost ~] # chown [- R] owner file or directory
The-R (note uppercase) option means that all files in the subdirectory are changed owners.
If you need to change both the owner and the group to which you belong, the basic format of the chown command is:
[root@localhost ~] # chown [- R] owner: group file or directory to which it belongs
Note that in the chown command, a dot (.) can also be used between the owner and the group to which it belongs, but there is a problem that if the user adds a decimal point (such as zhangsan.temp) when setting the account, it will cause the system to misjudge. Therefore, it is recommended that you use colons to connect the owner and the group to which you belong.
Of course, the chown command also supports simply modifying the group to which the file or directory belongs. For example, chown: group install.log means to modify the group to which the install.log file belongs, but the group to which it belongs usually uses the chgrp command, so it is not recommended to use the chown command.
Another point to note is that when you use the chown command to modify the owner (or owner) of a file or directory, make sure that the user user (or user group) exists, otherwise the command cannot be executed correctly and will prompt "invalid user" or "invaild group".
[example 1]
In fact, the owner of the file is changed more often in order to get higher permissions. Give me an example:
[root@localhost ~] # touch file# file file created by root user [root@localhost ~] # ll file-rw-r--r--. 1 root root 0 Apr 17 05:12 the owner of the file# file is root, and the ordinary user user has read-only access to this file [root@localhost ~] # chown user file# modify the owner of the file [root@localhost ~] # ll file-rw-r--r--. 1 user root 0 Apr 17 05:12 the file# owner becomes user, and the user user has read and write access to the file
As you can see, by changing the owner of the file file, the user user has changed from someone else (who only has read access to the file) to the owner, with read and write access to the file.
[example 2]
In the Linux system, the division of user level permissions is very clear. Root users have the highest permissions and can modify the permissions of any file, while ordinary users can only modify the permissions of their own files (the owner is their own file), for example:
[root@localhost ~] # cd / home/user# enter the user user's home directory [root@localhost user] # touch test# the file test [root@localhost user] # ll test-rw-r--r--. is created by the root user 1 root root 0 Apr 17 05:37 the owner and group of test# files are both root users [root@localhost user] # su-user# switched to user users [user@localhost ~] $chmod 755 testchmod: change the permissions for "test": disallowed operations # user users cannot modify permissions for test files [user@localhost ~] $exit# returns to root identity [root@localhost user] # chown user test# all test files are returned by root users Change to user user [root@localhost user] # su-user# switch to user user [user@localhost ~] $chmod 755 test#user user because it is the owner of the test file So you can modify the permissions of the file [user@localhost ~] $ll test-rwxr-xr-x. 1 user root 0 Apr 17 05:37 test# View permissions
As you can see, the user user does not have the right to change the permissions of the file owned by the root user, and only the ordinary user is the owner of the file.
[example 3]
[root@localhost ~] # chown user:group file [root@localhost ~] # ll file-rw-r--r--. 1 user group 0 Apr 17 05:12 file
Chmod command: permissions to modify files or directories
The chmod command sets file permissions in two ways, using numbers or symbols to change permissions.
1. The chmod command uses numbers to modify file permissions
In Linux system, the basic permissions of files are composed of 9 characters. Take rwxrw-r-x as an example, we can use numbers to represent each permission. The corresponding relationship between each permission and number is as follows:
R-- > 4
W-- > 2
X-- > 1
Because these nine characters belong to three types of users, each user identity contains three permissions (r, w, x). By adding the numbers corresponding to the three permissions, the final value can be used as the permissions of each user.
In the case of rwxrw-r-x, the right limits for owners, groups, and others are:
Owner = rwx = 4 "2" 1 = 7
Group = rw- = 4: 2 = 6
Others = rmurx = 4: 1 = 5
Therefore, the corresponding permission value for this permission is 765.
The basic format of the chmod command to modify file permissions using numbers is:
[root@localhost ~] # chmod [- R] permission value file name
The-R (uppercase) option means that all files in the subdirectory also modify the set permissions.
For example, you can modify the permissions of the .bashrc directory file by using the following command:
[root@localhost] # ls-al .bashrc-rw-r--r--. 1 root root 176Sep 22 2004. Bashrc [root@localhost] # chmod 777. Bashrc [root@localhost] # ls-al. Bashrc-rwxrwxrwx. 1 root root 176 Sep 22 2004 .bashrc
For another example, usually after we edit a Shell file batch file with Vim, the file permission is usually rw-rw-r-- (644), so if you want to make the file executable and do not allow others to modify the file, you only need to set the file's permission to rwxr-xr-x (755).
2. Chmod command uses letters to modify file permissions
Since the basic permissions of a file are three user identities (owner, group, and others) with three permissions (rwx), the chmod command uses u, g, o for three identities, and a for all identities (short for all). In addition, the chmod command still uses r, w, and x to represent read, write, and execute permissions, respectively.
The basic format of the chmod command that modifies file permissions using letters is shown in the following figure.
For example, if we want to set the permissions of the .bashrc file to rwxr-xr-x, we can execute the following command:
[root@localhost] # chmod uprirwx root@localhost. [bashrc] # ls-al .bashrc-rwxr-xr-x. 1 root root 176 Sep 22 2004 .bashrc
For another example, if you want to increase the write permissions for each user of the .bashrc file, you can use the following command:
[root@localhost] # ls-al. Bashrc-rwxr-xr-x. 1 root root 176Sep 22 2004. Bashrc [root@localhost ~] # chmod axiw. Bashrc [root@localhost] # ls-al. Bashrc-rwxrwxrwx. 1 root root 176 Sep 22 2004 .bashrc
Umask command: make new files and directories have default permissions
Linux assigns initial permissions to all newly created files and directories by using umask default permissions.
So how do we know the value of the default permission for umask? You can use the umask command directly:
[root@localhost ~] # umask0022#root users default to 0022, and ordinary users default to 0002
How to modify the default permissions of umask
The umask permission value can be directly modified by the following command:
[root@localhost ~] # umask 002 [root@localhost ~] # umask0002 [root@localhost ~] # umask 033 [root@localhost ~] # umask0033
However, the modified umask in this way is only temporarily valid and will fail once you restart or log in to the system. If you want the changes to take effect permanently, you need to modify the corresponding environment variable configuration file / etc/profile. For example:
[root@localhost ~] # vim / etc/profile... Omit part of the content. If [$UID-gt 199] & & ["'id-gn'" = "'id-un'"]; then umask 002 # use this umask value else umask 022 if the UID is greater than 199 (normal user). If UID is less than 199 (superuser), use this umask value fi... Omit part of the content...
This is a Shell script, it doesn't matter if you don't understand it, you just need to know that the umask of an ordinary user is defined by the first paragraph of the if statement, while the umask value of the superuser root is defined by the else statement. Modify this file, and the umask value will take effect permanently.
Thank you for your reading, the above is the content of "what is the linux modify authority command". After the study of this article, I believe you have a deeper understanding of what the linux modification authority command is, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.