How to add sudo permissions to a user in Linux environment

How to add sudo permissions to a user in Linux environment

sudo configuration file

The default configuration file for sudo is /etc/sudoers. Generally, the Linux-specified editing tool visudo is used. The advantage of this tool is that it can perform error checking. When adding rules that do not conform to the syntax rules, an error message will be prompted when saving and exiting. After configuration, you can switch to the authorized common user and use sudo -l to check which commands are executable or prohibited.

Each line in the /etc/sudoers file is a rule. The # sign in front of it is considered a comment and is not executed. If the rule is very long, it can be written in multiple columns and the \ sign can be used to continue the line.

The rules in /etc/sudoers can be divided into two categories: one is authorization rules, and the other is alias definitions. Alias ​​definitions are not required, but authorization rules are required.

Enter the root user and open the sudoers file

#
# This file MUST be edited with the 'visudo' command as root.
#
# Please consider adding local content in /etc/sudoers.d/ instead of
# directly modifying this file.
#
# See the man page for details on how to write a sudoers file.
#
Defaults env_reset
Defaults mail_badpass
Defaults secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"

# Host alias specification

# User alias specification

# Cmnd alias specification

# User privilege specification
root ALL=(ALL:ALL) ALL

# Allow members of group sudo to execute any command
%sudo ALL=(ALL:ALL) ALL

# See sudoers(5) for more information on "#include" directives:

#includedir /etc/sudoers.d

Example 1: To add sudo privileges to ordinary user lin, add the following line (user name ALL=(ALL) ALL) below the line "root ALL=(ALL)ALL" and save the file.

lin ALL=(ALL:ALL) ALL

Example 2: How to allow ordinary user lin to have the permission to restart the /etc/init.d/nagios script

lin ALL=NOPASSWD:/etc/init.d/nagios restart

Example 3: Allow ordinary user lin to have all superuser privileges without having to enter a password

lin ALL=(ALL)NOPASSWD:ALL

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

You may also be interested in:
  • Linux exposes Sudo privilege escalation vulnerability, any user can also run root commands
  • How to run sudo command without entering password in Linux
  • Delegating Privileges in Linux Using Sudo
  • Summary of the Differences between sudo, su and su - Commands in Linux
  • Summary of ten tips for sudo command in Linux system
  • How to use sudo su to add root permissions to ordinary users in Linux
  • Detailed explanation of the detailed configuration of sudo and its configuration file /etc/sudoers under Linux
  • Detailed explanation of sudo command in Linux system

<<:  Common front-end JavaScript method encapsulation

>>:  Detailed explanation of MySQL slow log query

Blog    

Recommend

Solutions to Mysql index performance optimization problems

The optimization created by MySQL is to add index...

Web page creation basic declaration document type description (DTD

Using CSS layout to create web pages that comply w...

Sharing the structure and expression principles of simple web page layout

Introduction to structure and performance HTML st...

Detailed explanation of linux nslookup command usage

[Who is nslookup?] 】 The nslookup command is a ve...

How to create an Nginx server with Docker

Operating environment: MAC Docker version: Docker...

Docker volumes file mapping method

background When working on the blockchain log mod...

Example of how to exit the loop in Array.forEach in js

Table of contents forEach() Method How to jump ou...

Introduction to the use of em in elastic layout in CSS3: How many pixels is 1em?

I have been using CSS for a long time, but I have...

Detailed usage of Linux text search command find

The find command is mainly used to find directori...

Steps to introduce PWA into Vue project

Table of contents 1. Install dependencies 2. Conf...

Detailed tutorial on installing Prometheus with Docker

Table of contents 1. Install Node Exporter 2. Ins...

Circular progress bar implemented with CSS

Achieve results Implementation Code html <div ...