In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article will explain in detail what are the common commands about users and permissions in Linux. The editor thinks it is very practical, so I share it with you for reference. I hope you can get something after reading this article.
First, check your identity
Id:Display user identity.
The output of this command shows the uid,gid and the group to which the user belongs.
Uid is user ID, which is given when the account is created.
Gid is the primary group ID and is the id of the main group. Of course, this user can also belong to other more groups.
User account information is defined in the / etc/passwd file, and group information is defined in the / etc/group file.
II. Chmod
Command name: chmod
The original meaning of the command: change the permissions mode of a file
Path where the command is located: / bin/chmod
Syntax: chmod [{ugo} {+-=} {rwx}] [file or directory] [mode=421] [file or directory]
Function description: change file or directory permissions.
User Type:
U:user, which actually means the owner
Group to which g:group belongs
O:others, other people.
The a:all owner, the combination of ugo, defaults to all if the user type is not specified.
+ add permissions,-remove permissions, = grant permissions directly
R is readable, w is writable, and x is executable.
It has different meanings for files and folders, such as a file called doc, which gives the owner wx permission: chmod u+wx doc
Third, use numbers to express permissions
The code is as follows:
Rafael 4
WMui 2
Xmuri 1
Add up the number of permissions for each group as permissions for the entire group, such as:
Rwx is 7 ~ (th) r ~ x is 5 ~ r ~-it's 4
Then rwxr-xr-- can be expressed as 754
More commonly used numbers: 7 (rwx), 6 (rw-), 5 (rmurx), 4 (rmure -), 0 (- -)
4. Umask command
Umask command function: display and set the default permissions of the file.
Umask command syntax: umask [- S]
-S: displays the default permissions for new files or directories in rwx form.
Perform umask:
Show 0022
First 0: special permission bit
022 user permission bits, permission mask value.
You need to subtract 022 from 777 to get 755, with three numbers representing the permissions of ugo (user,group,others), respectively.
Umask-S:
Uprirwx, gendrx, gendrx, overnrx.
Linux permission rules:
Files created by default cannot be granted executable x permissions for security reasons, and files cannot be executed by default.
You can use umask to change the default permissions in the form of umask plus mask values.
For example, if you want to change the permissions to 750,777 minus 750and the umask 027 command.
Change your identity Changing Identities
There are three ways to change your current identity in Linux:
1. Log out, and then log in with another account. Orz...) .
two。 Use the su command.
3. Use the sudo command.
A:su
Su:Run a Shell with Substitute User and Group IDs.
Su [- [l]] [user]
If you use the-l option (often abbreviated to -), the result is a login shell.
It means that the user's user environment will be loaded and the current work path will be replaced with the user's home path. If no user is specified, the default is superuser.
When you execute su -, you need to enter the password of superuser. After you successfully enter it, a new shell will be opened, the command prompt will change to # (before $), and the current working directory will become the home directory of superuser (/ root). If you want to exit, type exit, and you will return to the previous shell.
You can also execute a command directly:
The code is as follows:
Su-c 'command'
You need to put the command in quotation marks to make a distinction.
B:sudo
Sudo:Execute a Command as Another User.
Sudo is similar to su with some additional properties that administrators can configure sudo to allow ordinary users to execute commands in different identities under good control.
A user may be restricted to certain commands and cannot execute others.
Another difference is that sudo does not require to know the password of superuser, but only needs to know the password of the current user. After entering the password and completing the authentication, sudo will not open a new shell or load another user's environment, and the command does not need to be enclosed in quotes. This behavior can be overridden with various options, and you can view the man page of sudo.
Sudo-l can view the permissions granted by sudo.
Change the owner and the group to which it belongs
Change the owner: chown
The original meaning of the command: change file ownership
Syntax: chown [user] [file or directory]
Function: change the owner of a file or directory.
Change the group: chgrp
The original meaning of the command: change file group ownership
Syntax: chown [user group] [file or directory]
Function: change the group to which the file or directory belongs.
The chown command can also be used to change the group to which it belongs.
The code is as follows:
Chown [owner] [: [group]] file...
7. Change the password
Passwd [user]
When you reset the password, you need to enter the old password.
If you have access to superuser, you can also set the passwords of other users.
Other options can be set for account locking, password expiration, etc. For more information, please see passwd's man page.
This is the end of this article on "what are the common commands for users and permissions in Linux?". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.
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.