V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
Distributions
Ubuntu
Fedora
CentOS
中文资源站
网易开源镜像站
rizon
V2EX  ›  Linux

visudo 配置里面限制 hostname 有什么作用?

  •  
  •   rizon ·
    othorizon · 2018-09-30 14:42:58 +08:00 · 1912 次点击
    这是一个创建于 2249 天前的主题,其中的信息可能已经有所发展或是发生改变。
    今天了解了一下 sudo 的配置,然后对于第二列等号左边的 hostname 配置很疑惑,这个有什么用?
    不是所有登陆主机的人的 hostname 都是固定的吗?
    虽然可以修改这个值。但是这个限制到底有什么意义?
    是用在什么场合下的??
    6 条回复    2018-10-03 22:14:38 +08:00
    liwufan
        1
    liwufan  
       2018-09-30 17:47:29 +08:00
    你以为你了解了,其实是心急了。答案都在 /usr/share/doc /usr/share/man 里面
    ## Groups of machines. You may prefer to use hostnames (perhaps using
    ## wildcards for entire domains) or IP addresses instead.
    # Host_Alias FILESERVERS = fs1, fs2
    # Host_Alias MAILSERVERS = smtp, smtp2

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


    ##
    # User specification
    ##

    # root and users in group wheel can run anything on any machine as any user
    root ALL = (ALL) ALL
    %wheel ALL = (ALL) ALL

    # full time sysadmins can run anything on any machine without a password
    FULLTIMERS ALL = NOPASSWD: ALL

    # part time sysadmins may run anything but need a password
    PARTTIMERS ALL = ALL

    # jack may run anything on machines in CSNETS
    jack CSNETS = ALL

    # lisa may run any command on any host in CUNETS (a class B network)
    lisa CUNETS = ALL

    # operator may run maintenance commands and anything in /usr/oper/bin/
    operator ALL = DUMPS, KILL, SHUTDOWN, HALT, REBOOT, PRINTING,\
    sudoedit /etc/printcap, /usr/oper/bin/

    # joe may su only to operator
    joe ALL = /usr/bin/su operator

    # pete may change passwords for anyone but root on the hp snakes
    pete HPPA = /usr/bin/passwd [A-Za-z]*, !/usr/bin/passwd *root*

    # bob may run anything on the sparc and sgi machines as any user
    # listed in the Runas_Alias "OP" (ie: root and operator)
    bob SPARC = (OP) ALL : SGI = (OP) ALL

    # jim may run anything on machines in the biglab netgroup
    jim +biglab = ALL

    # users in the secretaries netgroup need to help manage the printers
    # as well as add and remove users
    +secretaries ALL = PRINTING, /usr/bin/adduser, /usr/bin/rmuser

    # fred can run commands as oracle or sybase without a password
    fred ALL = (DB) NOPASSWD: ALL

    # on the alphas, john may su to anyone but root and flags are not allowed
    john ALPHA = /usr/bin/su [!-]*, !/usr/bin/su *root*

    # jen can run anything on all machines except the ones
    # in the "SERVERS" Host_Alias
    jen ALL, !SERVERS = ALL

    # jill can run any commands in the directory /usr/bin/, except for
    # those in the SU and SHELLS aliases.
    jill SERVERS = /usr/bin/, !SU, !SHELLS

    # steve can run any command in the directory /usr/local/op_commands/
    # as user operator.
    steve CSNETS = (operator) /usr/local/op_commands/

    # matt needs to be able to kill things on his workstation when
    # they get hung.
    matt valkyrie = KILL

    # users in the WEBMASTERS User_Alias (will, wendy, and wim)
    # may run any command as user www (which owns the web pages)
    # or simply su to www.
    WEBMASTERS www = (www) ALL, (root) /usr/bin/su www

    # anyone can mount/unmount a cd-rom on the machines in the CDROM alias
    ALL CDROM = NOPASSWD: /sbin/umount /CDROM,\
    /sbin/mount -o nosuid\,nodev /dev/cd0a /CDROM
    rizon
        2
    rizon  
    OP
       2018-10-01 13:07:20 +08:00
    @liwufan
    可我还是不明白 这个主机名 比如你贴出来的例子里的 www 这些主机名是什么含义? 哪里来的?
    为什么一个系统会有多个主机名?
    liwufan
        3
    liwufan  
       2018-10-01 20:20:34 +08:00
    @rizon 你可以自己试试 https://tools.ietf.org/html/rfc1178
    #2 “这些主机名是什么含义? 哪里来的?为什么一个系统会有多个主机名?”
    为什么你要有网名姓名小名外号绰号学号工号身份证号护照号?大家说话都用“你”不行吗?或者说给自己起几十个外号行吗?顺其自然
    liwufan
        4
    liwufan  
       2018-10-01 21:06:53 +08:00
    @rizon 比如你贴出来的例子里的 www 这些主机名是什么含义?
    没有含义

    看站长的这贴 https://www.v2ex.com/t/74166
    www 名 name,v2ex.com 域 domain。dns 域名系统 domain name system。
    updateing
        5
    updateing  
       2018-10-02 07:33:33 +08:00 via Android
    参考 https://unix.stackexchange.com/questions/71684/the-host-variable-in-etc-sudoers,hostname 是给“一个 sudoers 文件给很多台机器用”这种情况设计的,各个机器只会应用适用于自己的主机名的规则。这样如果很多服务器要用同一套 sudo 规则的话,管理起来方便一点。楼上的回复也是 [doge]
    rizon
        6
    rizon  
    OP
       2018-10-03 22:14:38 +08:00 via iPhone
    @updateing 谢了哈,嗯,看起来是这么回事啊,居然就是为了这个。。。。


    @liwufan 谢谢哈,是我没有描述清楚了。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   4111 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 05:17 · PVG 13:17 · LAX 21:17 · JFK 00:17
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.