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


相关推荐

  • 关于ASP.NET编程中,GridView表格无法执行RenderControl()方法的问题

    关于ASP.NET编程中,GridView表格无法执行RenderControl()方法的问题当GridView表格控件设置了“自动排序”时,其RenderControl()方法运行时会报错。 

    2022年7月20日
    16
  • 快手用户群体分析_抖音、快手竞品分析报告

    快手用户群体分析_抖音、快手竞品分析报告一、产品初步体验介绍体验环境:RedmiNote5A体验时间:2018.7体验人:Cinnamon抖音快手抖音的logo以暗黑色为底,一个大大的亮白立体音符占据中央,强调了抖音重点在于结合音乐,给人的第一感觉就是炫酷,符合年轻人的审美。快手的logo以黄色为主,是一个立体的摄像机,体现了快手重点在于记录。应用首页抖音的底部button遵循传统的排版:刷新-附近/推荐(首页)、关注、拍摄、消息和我…

    2022年5月10日
    90
  • django 字段类型_access的数据库类型是

    django 字段类型_access的数据库类型是django模型中常见字段类型

    2025年9月20日
    6
  • 使用OSTaskCreate()建立一个任务后,该任务处于( )_worksheetfunction函数用法

    使用OSTaskCreate()建立一个任务后,该任务处于( )_worksheetfunction函数用法任务是操作系统处理的首要对象,在多任务运行的环境中,任务的管理需要考虑多方面的因素,最基本的任务管理是任务的创建。任务创建函数有两种,一种是基本的创建函数OSTaskCreate,另一种是扩展的任务创建函数OSTaskCreateExt。两个函数都实现了任务的创建,但是OSTaskCreateExt的功能更强,带有很多附加的功能,如果不需要附加功能,OSTaskCreate是完全可以胜任的,没有哪

    2025年9月22日
    6
  • bat time命令_bat获取文件修改时间

    bat time命令_bat获取文件修改时间最近公司的项目,需要部署一个oracle定时备份脚本,删除掉特定时间前的备份文件。BAT批处理文件结合windows系统(任务计划程序)正常情况下我们的任务计划会有反馈数值,通过它可以判断这个任务计划上次是否运行正常。代码0或0x0:操作成功完成。代码1或0x1:调用的函数不正确或调用了未知函数。代码10或0xa:环境不正确。代码0x8009000f…

    2026年1月28日
    7
  • datagrip 激活码【2021.8最新】

    (datagrip 激活码)2021最新分享一个能用的的激活码出来,希望能帮到需要激活的朋友。目前这个是能用的,但是用的人多了之后也会失效,会不定时更新的,大家持续关注此网站~IntelliJ2021最新激活注册码,破解教程可免费永久激活,亲测有效,下面是详细链接哦~https://javaforall.net/100143.html…

    2022年3月26日
    75

发表回复

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

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