如何分析Linux下的sudo及其配置文件/etc/sudoers的配置

发布时间:2022-01-21 14:19:03 作者:柒染
来源:亿速云 阅读:147

这篇文章的内容主要围绕如何分析Linux下的sudo及其配置文件/etc/sudoers的配置进行讲述,文章内容清晰易懂,条理清晰,非常适合新手学习,值得大家去阅读。感兴趣的朋友可以跟随小编一起阅读吧。希望大家通过这篇文章有所收获!


1.sudo介绍

如何分析Linux下的sudo及其配置文件/etc/sudoers的配置

sudo是linux下常用的允许普通用户使用超级用户权限的工具,允许系统管理员让普通用户执行一些或者全部的root命令,如halt,reboot,su等等。这样不仅减少了root用户的登陆 和管理时间,同样也提高了安全性。Sudo不是对shell的一个代替,它是面向每个命令的。

它的特性主要有这样几点:

 ############################################################# 
# 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 
##################################################

感谢你的阅读,相信你对“如何分析Linux下的sudo及其配置文件/etc/sudoers的配置”这一问题有一定的了解,快去动手实践吧,如果想了解更多相关知识点,可以关注亿速云网站!小编会继续为大家带来更好的文章!

推荐阅读:
  1. Linux 中不输入密码运行 sudo 命令的方法
  2. Linux下sudo及其配置文件/etc/sudoers的示例分析

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

linux sudo sudoers

上一篇:Linux系统如何查看版本

下一篇:nginx如何配置反向代理

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》