linux sudoers - sudo权限配置

【基本介绍】
The sudoers policy module determines a user's sudo privileges. It is the default sudo policy plugin. The policy is driven by the /etc/sudoers file or, optionally in LDAP.
/etc/sudoers 用来配置管理用户sudo权限

【基本配置】
## Allow root to run any commands anywhere
root ALL=(ALL) ALL

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

## Allows people in group wheel to run all commands 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

讲解:root ALL=(ALL) ALL
root表示被授权的用户,这里是根用户;
第一个ALL表示所有计算机;
第二个ALL表示所有用户;
第三个ALL表示所有命令;

通用格式
/etc/sudoers的通用格式为:
user host run_as command
user:一位或几位用户,在/etc/group中可以用一个%代替它,组对象的名称一定要用百分号%开头。
host:一个或几个主机名;
run_as:作为哪个用户运行,常见选项是root和ALL
command:想让用户或组运行的一个或几个根级别命令。

例如:
hans ALL=(root) useradd,userdel
授权hans用户在所有计算机上以root身份运行useradd,userdel命令。
%smith ALL=(ALL) NOPASSWD:useradd,userdel
授权smith组全部成员在所有计算机上以所有用户的身份运行useradd,userdel命令;且运行时不必输入密码。

--注意--
添加的命令最好要用全路径
如果命令有参数的话必须严格按照配置文件里面来
nagios ALL= NOPASSWD: /bin/cp /etc/shadow /home/nagios/haha
那么复制shadow也只能复制到名字为haha的文件,否则要输入密码

【异常】
提示sudo: sorry, you must have a tty to run sudo解决方法
方法1.注释#Defaults requiretty
方法2.添加Defaults:user !requiretty (指定user不需要tty)

【参考】
[url]http://www.sudo.ws/sudoers.man.html[/url]
[url]http://blog.chinaunix.net/uid-26642180-id-3962245.html[/url]
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值