linux普通用户添加root权限

  新增一个普通用户并进入该用户:

[root@VM_0_7_centos ~]# groupadd mall
[root@VM_0_7_centos ~]# useradd mall -m -d /home/mall -g mall -s /bin/bash
[root@VM_0_7_centos ~]# passwd mall
Changing password for user mall.
New password: 
BAD PASSWORD: The password is shorter than 8 characters
Retype new password: 
passwd: all authentication tokens updated successfully.
[root@VM_0_7_centos ~]# su - mall

  安装yum-utils失败了,提示需要root权限:

[mall@VM_0_7_centos ~]$ yum install -y yum-utils device-mapper-persistent-data lvm2
Loaded plugins: fastestmirror, langpacks
You need to be root to perform this command.

  使用sudo获取root权限:

[mall@VM_0_7_centos ~]$ sudo yum install -y yum-utils device-mapper-persistent-data lvm2

We trust you have received the usual lecture from the local System
Administrator. It usually boils down to these three things:

    #1) Respect the privacy of others.
    #2) Think before you type.
    #3) With great power comes great responsibility.

[sudo] password for mall: 
mall is not in the sudoers file.  This incident will be reported.

  它说该普通用户没有在sudoers文件里,切换回root:

[mall@VM_0_7_centos ~]$ su - root
Password: 
Last login: Wed Oct 30 16:00:38 CST 2019 from 202.101.145.54 on pts/1
Last failed login: Wed Oct 30 16:28:06 CST 2019 from 110.119.120.10 on ssh:notty
There were 799 failed login attempts since the last successful login.

  修改sudoers文件,加入写权限:

[root@VM_0_7_centos ~]# chmod +w /etc/sudoers
[root@VM_0_7_centos ~]# vi /etc/sudoers

  新增下面标红的那一行,把普通用户mall加进入:

   敲:wq保存后,撤销sudoers文件写权限:

[root@VM_0_7_centos ~]# chmod -w /etc/sudoers

  重新进入mall用户,下载yum-utils:

[root@VM_0_7_centos ~]# su - mall
Last login: Wed Oct 30 16:23:23 CST 2019 on pts/0
[mall@VM_0_7_centos ~]$ sudo yum -y install yum-utils device-mapper-persistent-data 1vm2
[sudo] password for mall: 
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
Package yum-utils-1.1.31-52.el7.noarch already installed and latest version
Package device-mapper-persistent-data-0.8.5-1.el7.x86_64 already installed and latest version
No package 1vm2 available.
Nothing to do

  这回可以了,不过其实已经安装过了,白折腾了。

原文地址:https://www.cnblogs.com/wuxun1997/p/11765905.html