理解 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)
上一篇 2022年6月20日 下午3:46
下一篇 2022年6月20日 下午4:00


相关推荐

  • Java GUI编程11—单选按钮:JRadioButton

    Java GUI编程11—单选按钮:JRadioButton认识JRadionButton单选按钮就是在给定的多个选择项中选择一个,并且只能选择一个。在Swing中可以使用JRadioButton完成一组单选按钮的操作,JRadioButton的常用方法如下表。序号方法描述123456…

    2022年5月30日
    49
  • pycharm没有setting_pycharm怎么配置python环境变量

    pycharm没有setting_pycharm怎么配置python环境变量问题:pycharm无法加载pip3安装包报错:pythonpackingtoolsnotfound.installpackingtools通过卸载重装pip3都没有用解决方法:更新一下setuptools就好啦sudopip3installsetuptools–upgradesudopipinstallsetuptools–upgrade…

    2022年8月27日
    10
  • 可视化数据库设计软件有哪些_数据库可视化编程

    可视化数据库设计软件有哪些_数据库可视化编程学习目标:C#数据库应用程序的开发环境的构成服务器资源管理器类型化数据集创建简单的数据库应用程序水晶报表Notes:类型化数据集利用服务器资源管理器建立数据连接利用服务器资源管理器可执行的任务如下:1)打开数据连接。2)登录到服务器上,并显示服务器的数据库和系统服务,包括事件日志、消息队列、性能计数器、系统服务和SQL数据库。3)查看关于可用Web服务的信息以及使信息…

    2022年4月20日
    56
  • 为什么会有内存屏障呢_内存出问题有什么现象

    为什么会有内存屏障呢_内存出问题有什么现象复习一下内存屏障主要解决指令重排和可见性,需要了解JMM架构原文链接为什么会有内存屏障每个CPU都会有自己的缓存(有的甚至L1,L2,L3),缓存的目的就是为了提高性能,避免每次都要向内存取。但是这样的弊端也很明显:不能实时的和内存发生信息交换,分在不同CPU执行的不同线程对同一个变量的缓存值不同。用volatile关键字修饰变量可以解决上述问题,那么volatile是如何做到这一点的呢?那就是内存屏障,内存屏障是硬件层的概念,不同的硬件平台实现内存屏障的手段并不是一样,java通过屏蔽这些差异,统

    2022年8月8日
    8
  • refit 尝试

    refit 尝试1 新的东西尝试真的很耗时 对 restapi 理解不够 dotnetframew 中的 demopost 一个 string 可以的 在 core 里面没有多想就 copy 过来 结果就是 bu cheng

    2026年3月20日
    2
  • 《启示录-打造用户喜爱的产品》-第一部分

    今天下午读了《启示录-打造用户喜爱的产品》的第一部分,介绍软件开发中的人员职能,其实主要还是产品经理相关的,做了一部分笔记如下。其实平时读书也一直在思考,应该怎么读书,很多读过的书当时很受启发,但是过段时间就会淡忘了,模糊记得一些内容,但是又好像没有什么作用。之后读书读到有启发的地方还是记录一下,回头看看应该也还是有收获的。不知道大家都是怎么读书,有好方法的也欢迎交流下。优秀产品经理的七个特点1、

    2022年3月11日
    44

发表回复

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

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