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


相关推荐

  • @RequestParam注解使用

    @RequestParam注解使用1、作用:@RequestParam:将请求参数绑定到你控制器的方法参数上(是springmvc中接收普通参数的注解)2、语法:语法:@RequestParam(value=”参数名”,required=”true/false”,defaultValue=””)value:参数名required:是否包含该参数,默认为true,表示该请求路径中必须包含该参数,如果不包含就报…

    2022年6月30日
    18
  • oracle 10g数据库连接时,错误ora12514 解决办法

    oracle 10g数据库连接时,错误ora12514 解决办法主要注意三点:1。在oracle安装目录下,..\oracle\product\10.2.0\db_1\NETWORK\ADMIN修改listener.ora文件,SID_LIST_LISTENER =  (SID_LIST =    (SID_DESC =      (SID_NAME = PLSExtProc)      (ORACLE_HOME = D:\oracle

    2022年7月15日
    34
  • CLion 2021.4激活码【在线破解激活】

    CLion 2021.4激活码【在线破解激活】,https://javaforall.net/100143.html。详细ieda激活码不妨到全栈程序员必看教程网一起来了解一下吧!

    2022年3月16日
    57
  • 手把手教你用UNet做医学图像分割系统

    手把手教你用UNet做医学图像分割系统兄弟们好呀,这里是肆十二,这转眼间寒假就要过完了,相信大家的毕设也要准备动手了吧,作为一名大作业区的UP主,也该蹭波热度了,之前关于图像分类和目标检测我们都出了相应的教程,所以这期内容我们搞波新的,我们用Unet来做医学图像分割。我们将会以皮肤病的数据作为示范,训练一个皮肤病分割的模型出来,用户输入图像,模型可以自动分割去皮肤病的区域和正常的区域。B站讲解视频:CSDN博客:代码地址:unet_42:基于Unet的医学影像分割系统(gitee.com)处理好的数据集和训练好的模型:更多相关的

    2022年6月15日
    19
  • 统计|方差分析拒绝原假设的LSD一般步骤及实现

    统计|方差分析拒绝原假设的LSD一般步骤及实现LSD是针对方差分析中已经拒绝原假设后的检验,或许也可以说先来个LSD假设检验可以支持原假设的

    2022年6月4日
    35
  • ireport使用_result with

    ireport使用_result with1.问题:IReport如何实现变量字段$F{propertyName}赋值为一个NULL对象时不显示”null”,而显示为空白?解决方法:选中动态单元格,右键选择属性,在弹出对话框TextField选项卡中选中Blankwhennull。思考:以往我们为IReport中变量字段赋值时会在程序或报表Textfieldexpression中用三目符号去判空,用I…

    2022年9月10日
    1

发表回复

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

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