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

vue3+ts+EsLint+Prettier standard code implementation

Table of contents use Use of EsLint Add a profile...

JavaScript to implement click to switch verification code and verification

This article shares the specific code of JavaScri...

Tips and precautions for using MySQL index

1. The role of index In general application syste...

Two ways to build Docker images

Table of contents Update the image from an existi...

Various types of MySQL indexes

What is an index? An index is a data structure th...

How to use filters to implement monitoring in Zabbix

Recently, when I was working on monitoring equipm...

Detailed steps to change the default password when installing MySQL in Ubuntu

Step 1: Enter the directory: cd /etc/mysql, view ...

Example of setting up a whitelist in Nginx using the geo module

Original configuration: http { ...... limit_conn_...

How to convert Chinese into UTF-8 in HTML

In HTML, the Chinese phrase “學好好學” can be express...

Detailed explanation of storage engine in MySQL

MySQL storage engine overview What is a storage e...

Docker custom network detailed introduction

Table of contents Docker custom network 1. Introd...

Summary of commonly used multi-table modification statements in Mysql and Oracle

I saw this question in the SQL training question ...

Select does not support double click dbclick event

XML/HTML CodeCopy content to clipboard < div c...