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


相关推荐

  • gcc命令和make命令[通俗易懂]

    gcc命令和make命令[通俗易懂]针对gcc,新建一个c语言文件:3.常用的有两个命令:-o将main.c预处理、编译、汇编并链接形成可执行文件main。-o选项用来指定输出文件的文件名。-S把.c文件编译成汇编文件.s查看汇编文件:其他还有把.s文件输出为.o文件的命令-c把.o文件链接为可执行文件的命令也是-o…

    2022年10月11日
    0
  • 【Android Tricks 6】ViewPager首页与尾页的滑动动作响应[通俗易懂]

    【Android Tricks 6】ViewPager首页与尾页的滑动动作响应

    2022年1月28日
    40
  • c#事务处理(sqlTransaction)

    c#事务处理(sqlTransaction)事务:///<summary>///删除考勤///</summary>///<paramname=”dto”>Id</param>///<returns></returns>publicResultEntity<bool>Dele…

    2022年5月6日
    45
  • Unity | Cinemachine FreeLook Camera「建议收藏」

    Unity | Cinemachine FreeLook Camera「建议收藏」FreeLookCamera是可以基于第三人称视角进行自由观察的虚拟相机。如下图所示,自由视角相机有上中下三个红圈,我们可以通过修改CinemachineFreeLook组件中的值来修改红圈的高度及大小。三个红圈由一个纵向的红线相连。通过改变YAxis及XAxis的Value可以修改虚拟相机的视角。 SplineCurvature决定纵向的紧绷状态。 TopRig、MiddleRig、BottomRig即三个红圈的属性。在CinemachineFreeL…

    2022年5月28日
    162
  • Centos7安装Promethus(普罗米修斯)监控系统完整版

    Centos7安装Promethus(普罗米修斯)监控系统完整版相关博文:1、Centos7安装Promethus(普罗米修斯)监控系统完整版2、Promethus(普罗米修斯)监控Mysql数据库3、Promethus(普罗米修斯)安装Grafana可视化图形工具4、Promethus的Grafana图形显示MySQL监控数据5、Promethus(普罗米修斯)的Grafana+onealert实现报警功能目录一、普罗米修斯…

    2022年6月5日
    33
  • 系统可用性「建议收藏」

    系统可用性「建议收藏」一个网站、系统的战术包括可用性战术、可修改性战术、性能战术、安全性战术、可测试性战术、易用性战术。质量需求指定了软件的响应,以实现业务目标,战术是影响质量属性响应的设计决策,构架策略是战术的集合,构架

    2022年6月30日
    18

发表回复

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

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