免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 4748 | 回复: 4
打印 上一主题 下一主题

[桌面系统] visudo 里想设置所有用户可以用 sudo 执行某个命令怎么设置? [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2012-05-25 11:31 |只看该作者 |倒序浏览
本帖最后由 clino 于 2012-05-25 11:33 编辑

我看了 https://help.ubuntu.com/community/Sudoers
里面的格式是
<user list> <host list> = <operator list> <tag list> <command list>
user list 比较好理解,但是想设成所有用户是不是用ALL
host list,operator list,tag list 这3个怎么理解?

我想这么设可以吧:
ALL ALL = (ALL) /usr/local/bin/somecmd

如果想设成不用输密码应该是这样吧:
ALL ALL = (ALL) NOPASSWD: /usr/local/bin/somecmd

主要还想问一下host list,operator list,tag list 这3个怎么理解?因为涉及到安全,所以想尽量搞清楚

论坛徽章:
13
15-16赛季CBA联赛之同曦
日期:2016-01-28 19:52:032015亚冠之北京国安
日期:2015-10-07 14:28:19NBA常规赛纪念章
日期:2015-05-04 22:32:03处女座
日期:2015-01-15 19:45:44卯兔
日期:2014-10-28 16:17:14白羊座
日期:2014-05-24 15:10:46寅虎
日期:2014-05-10 09:50:35白羊座
日期:2014-03-12 20:52:17午马
日期:2014-03-01 08:37:27射手座
日期:2014-02-19 19:26:54子鼠
日期:2013-11-30 09:03:56狮子座
日期:2013-09-08 08:37:52
2 [报告]
发表于 2012-05-25 11:55 |只看该作者
user  from=(switch to ?)  switch后可以使用的command

论坛徽章:
0
3 [报告]
发表于 2012-05-25 11:57 |只看该作者
ulovko 发表于 2012-05-25 11:55
user  from=(switch to ?)  switch后可以使用的command

呃...完全没看懂...

论坛徽章:
13
15-16赛季CBA联赛之同曦
日期:2016-01-28 19:52:032015亚冠之北京国安
日期:2015-10-07 14:28:19NBA常规赛纪念章
日期:2015-05-04 22:32:03处女座
日期:2015-01-15 19:45:44卯兔
日期:2014-10-28 16:17:14白羊座
日期:2014-05-24 15:10:46寅虎
日期:2014-05-10 09:50:35白羊座
日期:2014-03-12 20:52:17午马
日期:2014-03-01 08:37:27射手座
日期:2014-02-19 19:26:54子鼠
日期:2013-11-30 09:03:56狮子座
日期:2013-09-08 08:37:52
4 [报告]
发表于 2012-05-25 12:02 |只看该作者
回复 3# clino


    小声告诉你个秘密!

  1. >man sudoers
  2. EXAMPLES
  3.        Below are example sudoers entries.  Admittedly, some of these are a bit
  4.        contrived.  First, we allow a few environment variables to pass and
  5.        then define our aliases:

  6.         # Run X applications through sudo; HOME is used to find the
  7.         # .Xauthority file.  Note that other programs use HOME to find
  8.         # configuration files and this may lead to privilege escalation!
  9.         Defaults env_keep += "DISPLAY HOME"

  10.         # User alias specification
  11.         User_Alias     FULLTIMERS = millert, mikef, dowdy
  12.         User_Alias     PARTTIMERS = bostley, jwfox, crawl
  13.         User_Alias     WEBMASTERS = will, wendy, wim

  14.         # Runas alias specification
  15.         Runas_Alias    OP = root, operator
  16.         Runas_Alias    DB = oracle, sybase
  17.         Runas_Alias    ADMINGRP = adm, oper

  18.         # Host alias specification
  19.         Host_Alias     SPARC = bigtime, eclipse, moet, anchor :\
  20.                        SGI = grolsch, dandelion, black :\
  21.                        ALPHA = widget, thalamus, foobar :\
  22.                        HPPA = boa, nag, python
  23.         Host_Alias     CUNETS = 128.138.0.0/255.255.0.0
  24.         Host_Alias     CSNETS = 128.138.243.0, 128.138.204.0/24, 128.138.242.0
  25.         Host_Alias     SERVERS = master, mail, www, ns
  26.         Host_Alias     CDROM = orion, perseus, hercules

  27.         # Cmnd alias specification
  28.         Cmnd_Alias     DUMPS = /usr/bin/mt, /usr/sbin/dump, /usr/sbin/rdump,\
  29.                                /usr/sbin/restore, /usr/sbin/rrestore
  30.         Cmnd_Alias     KILL = /usr/bin/kill
  31.         Cmnd_Alias     PRINTING = /usr/sbin/lpc, /usr/bin/lprm
  32.         Cmnd_Alias     SHUTDOWN = /usr/sbin/shutdown
  33.         Cmnd_Alias     HALT = /usr/sbin/halt
  34.         Cmnd_Alias     REBOOT = /usr/sbin/reboot
  35.         Cmnd_Alias     SHELLS = /usr/bin/sh, /usr/bin/csh, /usr/bin/ksh, \
  36.                                 /usr/local/bin/tcsh, /usr/bin/rsh, \
  37.                                 /usr/local/bin/zsh
  38.         Cmnd_Alias     SU = /usr/bin/su
  39.         Cmnd_Alias     PAGERS = /usr/bin/more, /usr/bin/pg, /usr/bin/less

  40.        Here we override some of the compiled in default values.  We want sudo
  41.        to log via syslog(3) using the auth facility in all cases.  We don't
  42.        want to subject the full time staff to the sudo lecture, user millert
  43.        need not give a password, and we don't want to reset the LOGNAME, USER
  44.        or USERNAME environment variables when running commands as root.
  45.        Additionally, on the machines in the SERVERS Host_Alias, we keep an
  46.        additional local log file and make sure we log the year in each log
  47.        line since the log entries will be kept around for several years.
  48.        Lastly, we disable shell escapes for the commands in the PAGERS
  49.        Cmnd_Alias (/usr/bin/more, /usr/bin/pg and /usr/bin/less).

  50.         # Override built-in defaults
  51.         Defaults               syslog=auth
  52.         Defaults>root          !set_logname
  53.         Defaults:FULLTIMERS    !lecture
  54.         Defaults:millert       !authenticate
  55.         Defaults@SERVERS       log_year, logfile=/var/log/sudo.log
  56.         Defaults!PAGERS        noexec

  57.        The User specification is the part that actually determines who may run
  58.        what.

  59.         root           ALL = (ALL) ALL
  60.         %wheel         ALL = (ALL) ALL

  61.        We let root and any user in group wheel run any command on any host as
  62.        any user.

  63.         FULLTIMERS     ALL = NOPASSWD: ALL

  64.        Full time sysadmins (millert, mikef, and dowdy) may run any command on
  65.        any host without authenticating themselves.

  66.         PARTTIMERS     ALL = ALL

  67.        Part time sysadmins (bostley, jwfox, and crawl) may run any command on
  68.        any host but they must authenticate themselves first (since the entry
  69.        lacks the NOPASSWD tag).

  70.         jack           CSNETS = ALL

  71.        The user jack may run any command on the machines in the CSNETS alias
  72.        (the networks 128.138.243.0, 128.138.204.0, and 128.138.242.0).  Of
  73.        those networks, only 128.138.204.0 has an explicit netmask (in CIDR
  74.        notation) indicating it is a class C network.  For the other networks
  75.        in CSNETS, the local machine's netmask will be used during matching.

  76.         lisa           CUNETS = ALL

  77.        The user lisa may run any command on any host in the CUNETS alias (the
  78.        class B network 128.138.0.0).

  79.         operator       ALL = DUMPS, KILL, SHUTDOWN, HALT, REBOOT, PRINTING,\
  80.                        sudoedit /etc/printcap, /usr/oper/bin/

  81.        The operator user may run commands limited to simple maintenance.
  82.        Here, those are commands related to backups, killing processes, the
  83.        printing system, shutting down the system, and any commands in the
  84.        directory /usr/oper/bin/.

  85.         joe            ALL = /usr/bin/su operator

  86.        The user joe may only su(1) to operator.

  87.         pete           HPPA = /usr/bin/passwd [A-Za-z]*, !/usr/bin/passwd root

  88.         %opers         ALL = (: ADMINGRP) /usr/sbin/

  89.        Users in the opers group may run commands in /usr/sbin/ as themselves
  90.        with any group in the ADMINGRP Runas_Alias (the adm and oper groups).

  91.        The user pete is allowed to change anyone's password except for root on
  92.        the HPPA machines.  Note that this assumes passwd(1) does not take
  93.        multiple user names on the command line.

  94.         bob            SPARC = (OP) ALL : SGI = (OP) ALL

  95.        The user bob may run anything on the SPARC and SGI machines as any user
  96.        listed in the OP Runas_Alias (root and operator).

  97.         jim            +biglab = ALL

  98.        The user jim may run any command on machines in the biglab netgroup.
  99.        sudo knows that "biglab" is a netgroup due to the '+' prefix.

  100.         +secretaries   ALL = PRINTING, /usr/bin/adduser, /usr/bin/rmuser

  101.        Users in the secretaries netgroup need to help manage the printers as
  102.        well as add and remove users, so they are allowed to run those commands
  103.        on all machines.

  104.         fred           ALL = (DB) NOPASSWD: ALL

  105.        The user fred can run commands as any user in the DB Runas_Alias
  106.        (oracle or sybase) without giving a password.

  107.         john           ALPHA = /usr/bin/su [!-]*, !/usr/bin/su *root*

  108.        On the ALPHA machines, user john may su to anyone except root but he is
  109.        not allowed to specify any options to the su(1) command.

  110.         jen            ALL, !SERVERS = ALL

  111.        The user jen may run any command on any machine except for those in the
  112.        SERVERS Host_Alias (master, mail, www and ns).

  113.         jill           SERVERS = /usr/bin/, !SU, !SHELLS

  114.        For any machine in the SERVERS Host_Alias, jill may run any commands in
  115.        the directory /usr/bin/ except for those commands belonging to the SU
  116.        and SHELLS Cmnd_Aliases.

  117.         steve          CSNETS = (operator) /usr/local/op_commands/

  118.        The user steve may run any command in the directory
  119.        /usr/local/op_commands/ but only as user operator.

  120.         matt           valkyrie = KILL

  121.        On his personal workstation, valkyrie, matt needs to be able to kill
  122.        hung processes.

  123.         WEBMASTERS     www = (www) ALL, (root) /usr/bin/su www

  124.        On the host www, any user in the WEBMASTERS User_Alias (will, wendy,
  125.        and wim), may run any command as user www (which owns the web pages) or
  126.        simply su(1) to www.

  127.         ALL            CDROM = NOPASSWD: /sbin/umount /CDROM,\
  128.                        /sbin/mount -o nosuid\,nodev /dev/cd0a /CDROM

  129.        Any user may mount or unmount a CD-ROM on the machines in the CDROM
  130.        Host_Alias (orion, perseus, hercules) without entering a password.
  131.        This is a bit tedious for users to type, so it is a prime candidate for
  132.        encapsulating in a shell script.

  133. SECURITY NOTES
  134.        It is generally not effective to "subtract" commands from ALL using the
  135.        '!' operator.  A user can trivially circumvent this by copying the
  136.        desired command to a different name and then executing that.  For
  137.        example:

  138.            bill        ALL = ALL, !SU, !SHELLS

  139.        Doesn't really prevent bill from running the commands listed in SU or
  140.        SHELLS since he can simply copy those commands to a different name, or
  141.        use a shell escape from an editor or other program.  Therefore, these
  142.        kind of restrictions should be considered advisory at best (and
  143.        reinforced by policy).

  144.        Furthermore, if the fast_glob option is in use, it is not possible to
  145.        reliably negate commands where the path name includes globbing (aka
  146.        wildcard) characters.  This is because the C library's fnmatch(3)
  147.        function cannot resolve relative paths.  While this is typically only
  148.        an inconvenience for rules that grant privileges, it can result in a
  149.        security issue for rules that subtract or revoke privileges.

  150.        For example, given the following sudoers entry:

  151.         john   ALL = /usr/bin/passwd [a-zA-Z0-9]*, /usr/bin/chsh [a-zA-Z0-9]*,
  152.              /usr/bin/chfn [a-zA-Z0-9]*, !/usr/bin/* root

  153.        User john can still run /usr/bin/passwd root if fast_glob is enabled by
  154.        changing to /usr/bin and running ./passwd root instead.


复制代码

论坛徽章:
0
5 [报告]
发表于 2012-05-25 20:54 |只看该作者
本帖最后由 zjhxmjl 于 2012-05-25 21:27 编辑
clino 发表于 2012-05-25 11:31
我看了 https://help.ubuntu.com/community/Sudoers
里面的格式是
  =   

方法很简单:
  1. ALL ALL=NOPASSWD: /path/to/command
复制代码
the host list is a list of hosts or a host alias(服务器列表)
the operator list is a list of users they must be running as or a runas alias
the command list is a list of commands or a cmnd alias.
其实下面都有相应的实例:
  1. # This lets the webmasters run all the web commands on the machine
  2. # "webserver" provided they give a password
  3. WEBMASTERS webserver= WEB_CMDS
  4. # This lets the admins run all the admin commands on the servers
  5. ADMINS SERVERS= ADMIN_CMDS
  6. # This lets all the USERS run admin commands on the workstations provided
  7. # they give the root password or and admin password (using "sudo -u <username>")
  8. USERS WORKSTATIONS=(ADMINS) ADMIN_CMDS
  9. # This lets "harry" shutdown his own machine without a password
  10. harry harrys-machine= NOPASSWD: SHUTDOWN_CMDS
  11. # And this lets everybody print without requiring a password
  12. ALL ALL=(ALL) NOPASSWD: PRINTING_CMDS
复制代码

参考资料
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP