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-04-09 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

How to use the Linux sudo command, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain for you in detail, people with this need can come to learn, I hope you can gain something.

The Linux sudo command executes instructions as a system administrator, that is, instructions executed through sudo appear to be executed by root himself.

Permissions: there are users who appear in / etc/sudoers.

Grammar

Sudo-V

Sudo-h

Sudo-l

Sudo-v

Sudo-k

Sudo-s

Sudo-H

Sudo [- b] [- p prompt] [- u username/#uid]-s

Sudo 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)

Example

The 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

Show sudo settings

$sudo-L / / display sudo settings

Available options in a sudoers ``Defaults'' line:

Syslog: Syslog facility if syslog is being used for logging

Syslog_goodpri: Syslog priority to use when user authenticates successfully

Syslog_badpri: Syslog priority to use when user authenticates unsuccessfully

Long_otp_prompt: Put OTP prompt on its own line

Ignore_dot: Ignore'.' In $PATH

Mail_always: Always send mail when sudo is run

Mail_badpass: Send mail if user authentication fails

Mail_no_user: Send mail if the user is not in sudoers

Mail_no_host: Send mail if the user is not in sudoers for this host

Mail_no_perms: Send mail if the user is not allowed to run a command

Tty_tickets: Use a separate timestamp for each user/tty combo

Lecture: Lecture user the first time they run sudo

Lecture_file: File containing the sudo lecture

Authenticate: Require users to authenticate by default

Root_sudo: Root may run sudo

Log_host: Log the hostname in the (non-syslog) log file

Log_year: Log the year in the (non-syslog) log file

Shell_noargs: If sudo is invoked with no arguments, start a shell

Set_home: Set $HOME to the target user when starting a shell with-s

Always_set_home: Always set $HOME to the target user's home directory

Path_info: Allow some information gathering to give useful error messages

Fqdn: Require fully-qualified hostnames in the sudoers file

Insults: Insult the user when they enter an incorrect password

Requiretty: Only allow the user to run sudo if they have a tty

Env_editor: Visudo will honor the EDITOR environment variable

Rootpw: Prompt for root's password, not the users's

Runaspw: Prompt for the runas_default user's password, not the users's

Targetpw: Prompt for the target user's password, not the users's

Use_loginclass: Apply defaults in the target user's loginclass if there is one

Set_logname: Set the LOGNAME and USER environment variables

Stay_setuid: Only set the effective uid to the target user, not the real uid

Preserve_groups: Don't initialize the group vector to that of the target user

Loglinelen: Length at which to wrap log file lines (0 for no wrap)

Timestamp_timeout: Authentication timestamp timeout

Passwd_timeout: Password prompt timeout

Passwd_tries: Number of tries to enter a password

Umask: Umask to use or 0777 to use user's

Logfile: Path to logfile

Mailerpath: Path to mail program

Mailerflags: Flags for mail program

Mailto: Address to send mailto

Mailfrom: Address to send mailfrom

Mailsub: Subject line for mail messages

Badpass_message: Incorrect password message

Timestampdir: Path to authentication timestampdir

Timestampowner: Owner of the authentication timestamp dir

Exempt_group: Users in this group are exempt from password and PATH requirements

Passprompt: Default password prompt

Passprompt_override: If set, passprompt will override system prompt in all cases.

Runas_default: Default user to run commands as

Secure_path: Value to override user's $PATH with

Editor: Path to the editor for use by visudo

Listpw: When to require a password for 'list' pseudocommand

Verifypw: When to require a password for 'verify' pseudocommand

Noexec: Preload the dummy exec functions contained in 'noexec_file'

Noexec_file: File containing dummy exec functions

Ignore_local_sudoers: If LDAP directory is up, do we ignore local sudoers file

Closefrom: File descriptors > =% d will be closed before executing a command

Closefrom_override: If set, users may override the value of `closefrom' with the-C option

Setenv: Allow users to set arbitrary environment variables

Env_reset: Reset the environment to a default set of variables

Env_check: Environment variables to check for sanity

Env_delete: Environment variables to remove

Env_keep: Environment variables to preserve

Role: SELinux role to use in the new security context

Type: SELinux type to use in the new security context

Askpass: Path to the askpass helper program

Env_file: Path to the sudo-specific environment file

Sudoers_locale: Locale to use while parsing sudoers

Visiblepw: Allow sudo to prompt for a password even if it would be visisble

Pwfeedback: Provide visual feedback at the password prompt when there is user input

Fast_glob: Use faster globbing that is less accurate but does not access the filesystem

Umask_override: The umask specified in sudoers will override the user's, even if it is more permissive

Execute the previous command with root privileges

$sudo!

Edit text as a specific user

$sudo-u uggc vi ~ www/index.html

/ / Edit the index.html file in the www directory in the home directory as uggc user

List current permissions

Sudo-l

List the version information of sudo

Sudo-V what is the Linux system Linux is a free-to-use and free-spread UNIX-like operating system, is a POSIX-based multi-user, multi-task, multi-threaded and multi-CPU operating system, using Linux can run major Unix tools, applications and network protocols.

Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.

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