理解 sudo 和 sudoers[通俗易懂]

理解 sudo 和 sudoers[通俗易懂]在Linux上,只有root用户可以执行任何命令,其他用户必须使用sudo才可执行特殊的命令.sudo是通过sudoers进行配置的.默认配置/etc/sudoers:##ThisfileMUSTbeeditedwiththe’visudo’commandasroot.##Pleaseconsideraddinglocalcontentin/etc/sudoers.d/insteadof#directlymodifying

大家好,又见面了,我是你们的朋友全栈君。

Linux 上, 只有 root 用户可以执行任何命令, 其他用户必须使用 sudo 才可执行特殊的命令.

sudo 是通过 sudoers 进行配置的.

默认配置

/etc/sudoers:

#
# This file MUST be edited with the 'visudo' command as root.
#
# Please consider adding local content in /etc/sudoers.d/ instead of
# directly modifying this file.
#
# See the man page for details on how to write a sudoers file.
#
Defaults        env_reset
Defaults        mail_badpass
Defaults        secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin"

# Host alias specification

# User alias specification

# Cmnd alias specification

# User privilege specification
root    ALL=(ALL:ALL) ALL

# Members of the admin group may gain root privileges
%admin ALL=(ALL) ALL

# Allow members of group sudo to execute any command
%sudo   ALL=(ALL:ALL) ALL

# See sudoers(5) for more information on "#include" directives:

#includedir /etc/sudoers.d

添加配置

不建议直接修改默认配置文件, 我们可以使用 #include#includedir 添加自定义的配置文件.

/etc/sudoers.d/README:

#
# As of Debian version 1.7.2p1-1, the default /etc/sudoers file created on
# installation of the package now includes the directive:
# 
#       #includedir /etc/sudoers.d
# 
# This will cause sudo to read and parse any files in the /etc/sudoers.d 
# directory that do not end in '~' or contain a '.' character.
# 
# Note that there must be at least one file in the sudoers.d directory (this
# one will do), and all files in this directory should be mode 0440.
# 
# Note also, that because sudoers contents can vary widely, no attempt is 
# made to add this directive to existing sudoers files on upgrade.  Feel free
# to add the above directive to the end of your /etc/sudoers file to enable 
# this functionality for existing installations if you wish!
#
# Finally, please note that using the visudo command is the recommended way
# to update sudoers content, since it protects against many failure modes.
# See the man page for visudo for more information.
#

理解配置

root    ALL=(ALL:ALL) ALL

上面的配置表示: root 用户可以在 任意机器 上以 任意用户任意用户组任意组合 执行 任意命令.

  • root: 用户 (%admin 表示 用户组)
  • ALL=: 所有 host (sudoers 配置可能被用到多台机器上)
  • ALL:: 任意 用户
  • :ALL: 任意 用户组
  • ALL: 任意 命令

常见配置

允许用户使用 sudo 执行任意命令, 但需要输入用户密码

user ALL=(ALL:ALL) ALL

允许用户不需要密码使用 sudo 执行任意命令

user ALL=(ALL:ALL) NOPASSWD: ALL

参考文档

公众号: 源自开发者

原文链接: https://goworker.cn/posts/linux-sudoers/

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/151372.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • 中文常用停用词表(哈工大停用词表、百度停用词表[通俗易懂]

    中文常用停用词表(哈工大停用词表、百度停用词表[通俗易懂]中文常用停用词表(哈工大停用词表、百度停用词表等:https://github.com/goto456/stopwords

    2022年6月16日
    45
  • C++中string append函数的使用与字符串拼接「建议收藏」

    C++中string append函数的使用与字符串拼接「建议收藏」常用的函数原型:basic_string&append(constbasic_string&str);basic_string&append(constchar*str);basic_string&append(constbasic_string&str,size_typeindex,size

    2022年6月24日
    28
  • 千兆以太网在国产FPGA(智多晶)上的实现[通俗易懂]

    千兆以太网在国产FPGA(智多晶)上的实现[通俗易懂]**千兆以太网在国产FPGA(智多晶)上的实现闲来无事,想了想写点东西,顺带着记录一下自己学习的过程,其中千兆以太网这个模块是之前的一个项目任务,已经实现,但是想着自己在这里面也遇到过许多坑,所以写点东西,避免后来者遇到相同的问题,以后尽量避免事后总结,要做到边做边总结;在2020年国产化的大趋势下,国产芯片开始发展,在这样的时代背景下,我开始了千兆以太网的学习;实现的是简单千兆以太网的实现,利用udp协议、arp协议等千兆以太网的通信,在介绍具体操作流程的过程前,我先介绍一下千兆以太网的设计框架,

    2022年8月30日
    3
  • 递归就这么简单

    递归就这么简单

    2022年3月13日
    41
  • c# 调用Microsoft XPS Document Writer打印机,将Pdf文件转换成Xps文件「建议收藏」

    c# 调用Microsoft XPS Document Writer打印机,将Pdf文件转换成Xps文件「建议收藏」最近碰到个项目,其中有个需要将pdf文件转换成xps文件的功能,xps文件还算是新东西,所以基本没啥了解,通过一段时间的调查,本人算是找到了2个方法:  1)通过PDFNet第三发开发组件即可很容易的完成转换功能,并且还有其他针对pdf文件操作的功能,还是很强大的。当然啦,这个东     西是要买的,可以先下一个试用版先体验体验。    下载地址:http://w

    2022年5月4日
    312
  • PriorityQueue详解

    PriorityQueue详解作者:王一飞 ,叩丁狼高级讲师。原创文章,转载请注明出处。     概念PriorityQueue一个基于优先级的无界优先级队列。优先级队列的元素按照其自然顺序进行排序,或者根据构造队列时提供的Comparator进行排序,具体取决于所使用的构造方法。该队列不允许使用null元素也不允许插入不可比较的对象(没有实现Comparable接口的对象)。PriorityQueue队…

    2022年4月29日
    46

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号