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

How to use the Linux sudo command

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article mainly introduces "how to use the Linux sudo command". In daily operation, I believe many people have doubts about how to use the Linux sudo command. 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 "how to use the Linux sudo command". Next, please follow the editor to study!

Linux commonly used commands udo commands execute instructions as a system administrator, that is, instructions executed through sudo are as if they were executed by root himself.

Syntax sudo-Vsudo-hsudo-lsudo-vsudo-ksudo-ssudo-Hsudo [- b] [- p prompt] [- u username/#uid]-ssudo command parameter description:

-V displays the version number

-h will display the version number and instructions for the use of the instructions.

-l shows the permissions of himself (the user who executes the sudo)

-v because sudo will ask for the password when it is executed for the first time or not within N minutes (N default is five). This parameter is re-confirmed. If it exceeds N minutes, the password will also be asked.

-k will force the user to ask for a password the next time sudo is executed (with or without more than N minutes)

-b the instructions to be executed are executed in the background

-p prompt can change the prompt for asking password, where% u will be replaced with the user's account name, and% h will display the host name

-u username/#uid does not add this parameter, which means that the instruction is to be executed as root. If this parameter is added, the instruction can be executed as username (# uid is the user number of the username)

-s executes the shell specified by SHELL in the environment variable, or the shell specified in / etc/passwd

-H specifies the HOME (home directory) in the environment variable as the user's home directory to change identity (if the-u parameter is not added, it is the system administrator root)

Instructions to be executed by command as a system administrator (or change to someone else with-u)

Instance sudo command uses the

$sudo ls [sudo] password for hnlinux:hnlinux is not in the sudoers file. This incident will be reported. Specify the user to execute the command

# sudo-u userb ls-l display sudo settings

$sudo-L / / displays the sudo settings Available options in a sudoers ``Defaults'' line:syslog: Syslog facility if syslog is being used for loggingsyslog_goodpri: Syslog priority to use when user authenticates successfullysyslog_badpri: Syslog priority to use when user authenticates unsuccessfullylong_otp_prompt: Put OTP prompt on its own lineignore_dot: Ignore'. In $PATHmail_always: Always send mail when sudo is runmail_badpass: Send mail if user authentication failsmail_no_user: Send mail if the user is not in sudoersmail_no_host: Send mail if the user is not in sudoers for this hostmail_no_perms: Send mail if the user is not allowed to run a commandtty_tickets: Use a separate timestamp for each user/tty combolecture: Lecture user the first time they run sudolecture_file: File containing the sudo lectureauthenticate: Require users to authenticate by defaultroot_sudo: Root may run sudolog_host: Log the hostname in The (non-syslog) log filelog_year: Log the year in the (non-syslog) log fileshell_noargs: If sudo is invoked with no arguments Start a shellset_home: Set $HOME to the target user when starting a shell with-salways_set_home: Always set $HOME to the target user's home directorypath_info: Allow some information gathering to give useful error messagesfqdn: Require fully-qualified hostnames in the sudoers fileinsults: Insult the user when they enter an incorrect passwordrequiretty: Only allow the user to run sudo if they have a ttyenv_editor: Visudo will honor the EDITOR environment variablerootpw: Prompt for root's password, not the users'srunaspw: Prompt for the runas_default user's password, not the users'stargetpw: Prompt for the target user's password Not the users'suse_loginclass: Apply defaults in the target user's loginclass if there is oneset_logname: Set the LOGNAME and USER environment variablesstay_setuid: Only set the effective uid to the target user Not the real uidpreserve_groups: Don't initialize the group vector to that of the target userloglinelen: Length at which to wrap logfile lines (0 for no wrap) timestamp_timeout: Authentication timestamp timeoutpasswd_timeout: Password prompt timeoutpasswd_tries: Number of tries to enter a passwordumask: Umask to use or 0777 to use user'slogfile: Path to log filemailerpath: Path tomail programmailerflags: Flags for mail programmailto: Address to send mail tomailfrom: Address to send mail frommailsub: Subject line for mail messagesbadpass_message: Incorrect password messagetimestampdir: Path to authentication timestamp dirtimestampowner: Owner of the authentication timestamp Direxempt_group: Users in this group are exempt from password and PATH requirementspassprompt: Default password promptpassprompt_override: If set Passprompt will override system prompt in all cases.runas_default: Default user to run commands assecure_path: Value to override user's $PATH witheditor: Path to the editor for use by visudolistpw: When to require a password for 'list' pseudocommandverifypw: When to require a password for' verify' pseudocommandnoexec: Preload the dummy exec functions contained in 'noexec_file'noexec_file: File containing dummy exec functionsignore_local_sudoers: If LDAP directory is up, do we ignore local sudoers fileclosefrom: File descriptors > =% d will be closed before executing a commandclosefrom_override: If set Users may override the value of `closefrom' with the-C optionsetenv: Allow users to set arbitrary environment variablesenv_reset: Reset the environment to a default set of variablesenv_check: Environment variables to check for sanityenv_delete: Environment variables to removeenv_keep: Environment variables to preserverole: SELinux role to use in the new security contexttype: SELinux type to use in the new security contextaskpass: Path to the askpass helper programenv_file: Path to the sudo-specific environment filesudoers_locale: Locale to use while parsing sudoersvisiblepw: Allow sudo to prompt for a password even if it would be visisblepwfeedback: Provide visual Feedback at the password prompt when there is user inputfast_glob: Use faster globbing that is less accurate but does not access the filesystemumask_override: The umask specified in sudoers will override the user's Even if it is more permissive executes the previous command with root privileges

$sudo! Edit text as a specific user

$sudo-u uggc vi ~ www/index.html// as uggc user edits the index.html file in the www directory under the home directory to list the current permissions

Sudo-l lists the version information of sudo

Sudo-V at this point, the study of "how to use the Linux sudo command" 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.

Share To

Development

Wechat

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

12
Report