In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces "the usage of su and sudo commands in Linux system". In daily operation, I believe many people have doubts about the usage of su and sudo commands in Linux system. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts about "the usage of su and sudo commands in Linux system". Next, please follow the editor to study!
Su
NAME (name)
Su-run shell that replaces user and group identities
SYNOPSIS (Overview)
Su [OPTION]... [-] [USER [ARG]...]
DESCRIPTION (description)
Modify the valid user ID and group ID to USER.
-.-l.-- login.
Make shell a loggable shell
-c,-- commmand=COMMAND
Pass a single COMMAND to-c's shell.
-f,-- fast
Pass-f to shell (for csh or tcsh)
-m,-- preserve-environment
Do not reset environment variables
-p is the same as-m
-s-- shell=SHELL
If / etc/shells allows, run SHELL.
-- help displays help and exits
-- version
Output version information and exit
Single-means-l. If no USER is given, it is assumed to be root.
Example:
The code is as follows:
[root@Blackghost ~] su zhangying # switch user, original user environment variable
[root@Blackghost ~] su-zhangying # switch users, new user environment variables
[zhangying@Blackghost ~] su-c ls root # switch the user to execute the command and return to the original user after execution
Sudo
Users can also use su to switch to root users to run commands. However, unlike su's launching a root shell that allows the user to run all subsequent commands, sudo can grant temporary permissions to a single command. Sudo only grants user permissions when needed, reducing the possibility that the user will damage the system due to incorrect command execution. Sudo can also be used to execute commands as other users. In addition, sudo can record commands executed by the user, as well as failed privilege acquisition.
Options:
-a type uses the specified BSD authentication type
-b run commands in the background
-C fd turns off all file descriptors that > = fd
-E preserves the user environment when executing the command
-e edit the file instead of executing the command
-g group executes commands in the specified user group
-H sets the HOME variable to the home directory of the target user.
-h displays a help message and exits
-I [command] run a login shell as the target user
-K completely removes the timestamp file
-k invalid timestamp file
-l [l] command lists the commands that the user can execute
-n non-interactive mode, users will not be prompted
-P retains the group vector instead of the group vector set as the target
-p prompt prompts with the specified password
-S read password from standard input
-s [command] runs shell as the target user
-U user lists the permissions of the specified user in the list
-u user runs the command (or edit the file) as the specified user
-V displays version information and exits
-v update the user's timestamp without executing the command
-- stop processing command line arguments
Example:
The code is as follows:
[root@Blackghost ~] sudo-u tank ls # executes ls commands as tank users
[zhangying@Blackghost ~] sudo touch test # creates a file test with a root account. If it is empty, it defaults to root users.
At this point, the study of "the use of su and sudo commands in the Linux system" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
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.