admin管理员组文章数量:1568133
在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
版权声明:本文标题:Linux 其他用户(非root用户)设置root权限及免密(Centos7为例) 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://www.elefans.com/dianzi/1727081316a1096872.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论