理解 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)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • 内网渗透综述

    内网渗透综述目录一 什么是内网渗透二 内网基础知识三 内网渗透基本流程一 什么是内网渗透内网是一个只有组织工作人员才能访问的专用网络 简而言之就是不可简单地通过外部公网 ip 进行访问到的公司内部网络 对于一个大型公司的网络系统 通过信息收集找到网站漏洞可以顺利通过公网进入公司内部网络时 进一步对公司内部网络的渗透攻击即为内网渗透 与外网渗透区别 1 外网渗透更侧重于找漏洞寻找突破口 考验的是白帽的综合能力 外网渗透的最终还是为了进入内网

    2025年9月8日
    2
  • 领域驱动实践总结(基本理论总结与分析+架构分析与代码设计+具体应用设计分析V)[通俗易懂]

    领域驱动设计DDD是一种设计思想,它可以同时指导中台业务建模和微服务设计(中台本质是业务模型,微服务是业务模型的系统落地),领域驱动设计强调领域模型和微服务设计的一体性,先有领域模型然后才有微服务,而不是脱离领域模型来谈微服务设计。

    2022年4月6日
    73
  • springboottest 红_解决没有@RunWith 和 @SpringBootTest注解或失效问题[通俗易懂]

    springboottest 红_解决没有@RunWith 和 @SpringBootTest注解或失效问题[通俗易懂]导入别人的项目或者自己想创建一个测试类经常会遇见了这个问题没有@RunWith和@SpringBootTest注解或失效网上搜了搜全是我下面的第一个解决方案第二个才是重点解决方案1添加依赖如果你是springboot项目pom文件中添加org.springframework.bootspring-boot-starter-testtestMaven项目在项目上右键B…

    2022年5月25日
    252
  • 在Ubuntu下编译Assimp库

    在Ubuntu下编译Assimp库

    2022年1月25日
    39
  • 一起学JAVA 学习路径 知识体系

    JAVA基础学习路径Java基础部分需要学习很多的内容,但是很多小伙伴不清楚自己的学习路径希望本文可以帮助到你,本文是程序媛泡泡给大家总结的链接汇总,欢迎食用因为泡泡平时比较忙,所以文章在逐步更新拓展中,可以关注后方便后续查看哦祝愿大家都能拥抱技术,扬帆起航????01计算机基础知识与JAVA相关基础知识02JAVA编程环境搭建:安装JDK与配置环境变量、Eclipse03JAVA入门案例之HelloWorld练习与解析…

    2022年4月6日
    54
  • NetCMS修改之二:单击新闻附件,直接打开文件「建议收藏」

    NetCMS修改之二:单击新闻附件,直接打开文件「建议收藏」   NetCMS系统的新闻附件,是通过down.aspx页面实现下载附件的。这样做的好处可能是可以隐藏附件的真实地址,但给用户使用会带来一个小麻烦:无法使用右键单击来实现将下载的文件另存为。   经检查,此功能是在NetCMS.Publish命名空间的LabelMass类中定义的getNewsFiles实现的,文件位于NetCMS.Publish/Label/NewsParameter.

    2022年9月29日
    2

发表回复

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

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