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

Recommend

Why should css be placed in the head tag

Think about it: Why should css be placed in the h...

Implementation of master-slave replication in docker compose deployment

Table of contents Configuration parsing Service C...

In-depth understanding of MySQL master-slave replication thread state transition

Preface The basic principle of MySQL master-slave...

MySQL query optimization using custom variables

Table of contents Optimizing sorting queries Avoi...

Detailed explanation of how to select all child elements using CSS

How to recursively select all child elements usin...

Example code for implementing dynamic skinning with vue+element

Sometimes the theme of a project cannot satisfy e...

The core process of nodejs processing tcp connection

A few days ago, I exchanged some knowledge about ...

How to deploy your first application with Docker

In the previous article, you have installed Docke...

You may need a large-screen digital scrolling effect like this

The large-screen digital scrolling effect comes f...

Dynamically edit data in Layui table row

Table of contents Preface Style Function Descript...

Implementation code for operating mysql database in golang

Preface Golang provides the database/sql package ...

In-depth explanation of currying of JS functions

Table of contents 1. Supplementary knowledge poin...

Introduction to scheduled tasks in Linux system

Table of contents 1. Customize plan tasks 2. Sync...

Detailed explanation of rpm installation in mysql

View installation and uninstallation # View rpm -...