CentOS下使用免密使用sudo命令

配置文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
## Allow root to run any commands anywhere 
root ALL=(ALL) ALL

## Allows members of the 'sys' group to run networking, software,
## service management apps and more.
# %sys ALL = NETWORKING, SOFTWARE, SERVICES, STORAGE, DELEGATING, PROCESSES, LOCATE, DRIVERS

## Allows people in group wheel to run all commands
%wheel ALL=(ALL) ALL

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

## Allows members of the users group to mount and unmount the
## cdrom as root
# %users ALL=/sbin/mount /mnt/cdrom, /sbin/umount /mnt/cdrom

## Allows members of the users group to shutdown this system
# %users localhost=/sbin/shutdown -h now

## Read drop-in files from /etc/sudoers.d (the # here does not mean a comment)
#includedir /etc/sudoers.d

上面配置中 %wheel ALL=(ALL) ALL 代表wheel组里面所有人可以使用所有命令

完整配置

1
2
3
4
5
6
7
8
[root@ipason ~]# groupadd   test
[root@ipason ~]# useradd -G test name1
[root@ipason ~]# id name1
uid=501(name1) gid=502(name1) groups=502(name1),501(test)

vim /etc/sudoers
# %test ALL=(ALL) ALL
%test ALL=(ALL) NOPASSWD: ALL

如果也可以在 /etc/sudoers.d 下面新建文件

1
2
vim   test_sudoers 
%test ALL=(ALL) NOPASSWD: ALL
  • 版权声明: 本博客所有文章除特别声明外,著作权归作者所有。转载请注明出处!
  • Copyrights © 2019-2023 XIN LONG
  • 访问人数: | 浏览次数:

请我喝杯咖啡吧~

支付宝
微信