用户加入sudoer"/>
Linux 下将用户加入sudoer
1. 加入sudoer前非root 用户不能使用sudo,所以如果是非root用户修改sudoer需要先切换到root 用户:
[auto@eagle ~]$ su root
Password: (root 的 password)
[root@eagle auto]#
2. 通过ls -altr 命令可以看到 即使是root 用户 sudoers 文件也只有可读权限,所以需要修改sudoers 文件权限:
[auto@eagle ~]$ ls -altr /etc/sudoers
-r--r-----. 1 root root 4328 Nov 28 2019 /etc/sudoers[auto@eagle ~]$ su root
Password:[root@eagle auto]# chmod 660 /etc/sudoers #给root用户和组的写权限
[root@eagle auto]# vim /etc/sudoers #进入vim编辑
3. 将用户或者组添加到 sudoers,并保存文件。
找到 “root ALL=(ALL) ALL” 这一行,在它的下面将需要的用户按照这个格式添加进去, auto就是需要添加的用户
## Allow root to run any commands anywhere
root ALL=(ALL) ALL
auto ALL=(ALL) ALL也可以将group添加到sudoers,wheel 是需要添加的group。
## Allows people in group wheel to run all commands
%wheel ALL=(ALL) ALL如果想在使用 sudoers 的时候不输入密码还可以通过NOPASSWD来设置。
# User privilege specification
root ALL=(ALL:ALL) ALL
jenkins ALL=(ALL:ALL) NOPASSWD:ALL
4. 用户添加成功后 将sudoers 的权限改回去
[root@eagle auto]# chmod 440 /etc/sudoers
[root@eagle auto]# ll /etc/sudoers
-r--r-----. 1 root root 4346 May 24 20:26 /etc/sudoers
[root@eagle auto]#
更多推荐
Linux 下将用户加入sudoer
发布评论