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

  這回可以了,不過其實已經安裝過了,白折騰了。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM