Linux 下将用户加入sudoer

编程入门 行业动态 更新时间:2024-10-07 14:25:47

Linux 下将<a href=https://www.elefans.com/category/jswz/34/1771412.html style=用户加入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

本文发布于:2024-02-17 18:10:51,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1694982.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:用户   Linux   sudoer

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!