普通用户---root权限

sudo是linux下常用的允许普通用户使用终极用户权限的工具。
他的主要设置文件是sudoers,linux下通常在/etc目录下,如果是solaris,缺省不装sudo的,编译安装后通常在安装目录的etc目录下,不过不管sudoers文件在哪儿,sudo都提供了一个编辑该文件的命令:visudo来对该文件进行修改。强烈推荐使用该命令修改 sudoers,因为他会帮你校验文件设置是否正确,如果不正确,在保存退出时就会提示你哪段设置出错的。
言归正传,下面介绍怎么设置sudoers
首先写sudoers的缺省设置:
#############################################################
# sudoers file.
#
# This file MUST be edited with the ’visudo’ command as root.
#
# See the sudoers man page for the details on how to write a sudoers file.
#
# Host alias specification
# User alias specification
# Cmnd alias specification
# Defaults specification
# User privilege specification
root    ALL=(ALL) ALL
# Uncomment to allow people in group wheel to run all commands
# %wheel        ALL=(ALL)       ALL
# Same thing without a password
# %wheel        ALL=(ALL)       NOPASSWD: ALL
# Samples
# %users  ALL=/sbin/mount /cdrom,/sbin/umount /cdrom
# %users  localhost=/sbin/shutdown -h now
##################################################################
1. 最简单的设置,让普通用户support具有root的所有权限
执行visudo之后,能看见缺省只有一条设置:
root    ALL=(ALL) ALL
那么你就在下边再加一条设置:
support ALL=(ALL) ALL
这样,普通用户support就能够执行root权限的所有命令
以support用户登录之后,执行:
sudo su -
然后输入support用户自己的密码,就能转换成root用户了
2. 让普通用户support只能在某几台服务器上,执行root能执行的某些命令
首先需要设置一些Alias,这样在下面设置权限时,会方便一些,不用写大段大段的设置。Alias主要分成4种
Host_Alias
Cmnd_Alias
User_Alias
Runas_Alias
1) 设置Host_Alias:就是主机的列表
Host_Alias      HOST_FLAG = hostname1, hostname2, hostname3
2) 设置Cmnd_Alias:就是允许执行的命令的列表
Cmnd_Alias      COMMAND_FLAG = command1, command2, command3
3) 设置User_Alias:就是具有sudo权限的用户的列表
User_Alias USER_FLAG = user1, user2, user3
4) 设置Runas_Alias:就是用户以什么身份执行(例如root,或oracle)的列表
Runas_Alias RUNAS_FLAG = operator1, operator2, operator3
5) 设置权限
设置权限的格式如下:
USER_FLAG HOST_FLAG=(RUNAS_FLAG) COMMAND_FLAG
如果不必密码验证的话,则按照这样的格式来设置
USER_FLAG HOST_FLAG=(RUNAS_FLAG) NOPASSWD: COMMAND_FLAG
设置示例:
############################################################################
# sudoers file.
#
# This file MUST be edited with the ’visudo’ command as root.
#
# See the sudoers man page for the details on how to write a sudoers file.
#
# Host alias specification
Host_Alias      EPG = 192.168.1.1, 192.168.1.2
# User alias specification
# Cmnd alias specification
Cmnd_Alias      SQUID = /opt/vtbin/squid_refresh, /sbin/service, /bin/rm
# Defaults specification
# User privilege specification
root    ALL=(ALL) ALL
support EPG=(ALL) NOPASSWD: SQUID
# Uncomment to allow people in group wheel to run all commands
# %wheel        ALL=(ALL)       ALL
# Same thing without a password
# %wheel        ALL=(ALL)       NOPASSWD: ALL
# Samples
# %users  ALL=/sbin/mount /cdrom,/sbin/umount /cdrom
# %users  localhost=/sbin/shutdown -h now
###############################################################

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值