Linux 其他用户(非root用户)设置root权限及免密(Centos7为例)

        在linux系统中我们经常要创建一些非root用户来完成一些特定的操作,有时我们需要执行一些root用户才能执行的命令,这时我们需要给该用户设置root的权限,下面将演示如何操作:

1、首先创建一个test用户,

[root@smiletian ~]# groupadd -g 1234 tian
[root@smiletian ~]# useradd -u 1234 -g tian test
[root@smiletian ~]# passwd test 
Changing password for user test.
New password: 
Retype new password: 
passwd: all authentication tokens updated successfully.

2、切换到test用户下,当我们执行sudo命令时,会提示输test用户密码,输完后提示,test用户不在sudoer文件里,所以是无法执行sudo命令的。

[root@smiletian test]# su - test
Last login: Sun Sep 18 23:35:57 PDT 2022 on pts/2
[test@smiletian ~]$ sudo mkdir abc
[sudo] password for test: 
test is not in the sudoers file.  This incident will be reported.

3、切换到root用户,编辑 /etc/sudoers文件

[test@smiletian ~]$ su
Password: 
[root@smiletian test]# vi /etc/sudoers

        找到  ## Allow root to run any commands anywhere 这栏,在root下添加 test用户,

## Allow root to run any commands anywhere
root    ALL=(ALL)       ALL
test    ALL=(ALL)       ALL

         找到## Same thing without a password一栏,将%wheel ALL=(ALL)前面的#去掉,

更改前
## Same thing without a password
#%wheel ALL=(ALL)       NOPASSWD: ALL

更改后:
## Same thing without a password
%wheel ALL=(ALL)       NOPASSWD: ALL

       wq!保存退出。

4、切换到test用户下,可以使用sudo命令,输入一次密码后,不再需要再每次都输入密码即可进行操作。

[root@smiletian test]# su - test
Last login: Sun Sep 18 23:54:07 PDT 2022 on pts/2
[test@smiletian ~]$ su
Password: 
[root@smiletian test]# vi /etc/sudoers
[root@smiletian test]# su - test
Last login: Mon Sep 19 00:08:24 PDT 2022 on pts/2
[test@smiletian ~]$ sudo mkdir abc
[sudo] password for test: 
[test@smiletian ~]$ sudo mkdir abd
[test@smiletian ~]$ sudo mkdir abf
[test@smiletian ~]$ ll
total 0
drwxr-xr-x. 2 root root 6 Sep 19 00:20 abc
drwxr-xr-x. 2 root root 6 Sep 19 00:20 abd
drwxr-xr-x. 2 root root 6 Sep 19 00:21 abf
  • 2
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

宇宙超级无敌天下第一雷霆霹雳爆龙战士

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值