zoukankan      html  css  js  c++  java
  • visudo精确用户赋权(sudo)

    原文BLOG:http://iminmin.blog.51cto.com/689308/455992
    sudo” 是Unix/Linux平台上的一个非常有用的工具,允许为非根用户赋予一些合理的“权利”,让他们执行一些只有根用户或特许用户才能完成的任务,从而减少根用户的登陆次数和管理时间同时也提高了系统安全性。

    • sudo的目的:为非根用户授予根用户的权限;
    • 配置文件:/etc/sudoers
    • visudo命令编辑修改/etc/sudoers配置文件

    1、一般用户赋权设置:

    [root@localhost ~]# visudo
    ……前面省略

    69 ## Syntax:

    70 ##

    71 ##      user    MACHINE=COMMANDS

    72 ##

    73 ## The COMMANDS section may have other options added to it.

    74 ##

    75 ## Allow root to run any commands anywhere

    76 root    ALL=(ALL)       ALL

    77 test   ALL=(root) /usr/sbin/useradd         //新增加用户行
    ……后面省略

            说明:
            第一个字段:root为能使用sudo命令的用户;
            第二个字段:第一个ALL为允许使用sudo的主机,第二个括号里的ALL为使用sudo后以什么身份(目的用户身份)来执行命令;
            第三个字:ALL为以sudo命令允许执行的命令;
      上列解释: test   ALL=(root) /usr/sbin/useradd
    表示允许test用户从任何主机登录,以root的身份执行/usr/sbin/useradd命令。
    用户执行命令效果:

    [root@server ~]# su - redhat
    [redhat@server ~]$ sudo /usr/sbin/useradd test
    //命令需要输入完整的路径
    口令:                                     //这里输入用户redhat自己的密码
    [redhat@server ~]$ cat /etc/passwd |tail -5
    xfs:x:43:43:X Font Server:/etc/X11/fs:/sbin/nologin
    gdm:x:42:42::/var/gdm:/sbin/nologin
    sabayon:x:86:86:Sabayon user:/home/sabayon:/sbin/nologin
    redhat:x:500:500::/home/redhat:/bin/bash
    test:x:501:501::/home/test:/bin/bash            //新增加的用户

    2、sudo配置深入:
             1)多个用户的设置(非同一群组用户):
    u 对于不同需求的用户:可以按照上面的方法依次增加多行,每行对应一个用户。
    u 对于相同需求的多个用户
    User_Alias UUU=user1,user2……             定义用户别名;

    [root@localhost ~]# visudo
    ……前面省略
    16 ## User Aliases
    17 ## These aren't often necessary, as you can use regular groups
    18 ## (ie, from files, LDAP, NIS, etc) in this file - just use %groupname
    19 ## rather than USERALIAS
    20 # User_Alias ADMINS = jsmith, mikem      //这个就是一个实例行,按照这个写自己的
    21 User_Alisa sudouser=user1,user2,user3,user4 //第一一个别名suduouser
    ……后面省略

    69 ## Syntax:

    70 ##

    71 ##      user    MACHINE=COMMANDS

    72 ##

    73 ## The COMMANDS section may have other options added to it.

    74 ##

    75 ## Allow root to run any commands anywhere

    76 root    ALL=(ALL)       ALL

    77 sudouser   ALL=(root)    /usr/sbin/useradd  ////命令行书写格式,用户列用别名
    ……后面省略

    对于多个命令的设置:

    [root@localhost ~]# visudo
    ……前面省略
    23 ## Command Aliases
    24 ## These are groups of related commands...
    25
    26 ## Networking
    27 Cmnd_Alias NETWORKING = /sbin/route, /sbin/ifconfig, /bin/ping, /sbin/dh        client, /usr/bin/net, /sbin/iptables, /usr/bin/rfcomm, /usr/bin/wvdial,         /sbin/iwconfig, /sbin/mii-tool                                                     //多个命令定义一个命令别名;
    ……后面省略

    69 ## Syntax:

    70 ##

    71 ##      user    MACHINE=COMMANDS

    72 ##

    73 ## The COMMANDS section may have other options added to it.

    74 ##

    75 ## Allow root to run any commands anywhere

    76 root    ALL=(ALL)       ALL

    77 sudouser   ALL=(root)    NETWORKING  //命令行书写格式,命令列用别名
    ……后面省略

    Cmnd_Alias CCC=command1,command2……          定义命令别名;
    对于多主机的设置和多登陆角色的设置:
    •修改 Host_Alias HHH=host1,host2……
    定义主机别名;
    修改后对应的命令行主机列位置也是用别名
    •Runas_Alias   RRR=role1,role2……                定义runas别名,指定的是“目的用户”,即sudo 允许转换至的用户;
    建立相关别明后,相关命令行相应的列也是用我们定义的别名。

             2)多个用户的设置(同一群组用户):

    [root@localhost ~]# visudo
    ……前面省略
    81
    82## Allows people in group wheel to run all commands
    83# %wheel        ALL=(ALL)       ALL        //用户列%+群组名
    ……后面省略

    END,希望大家能够合理为个用户账号授权。

  • 相关阅读:
    阮一峰的网络日志 算法
    Problem 2184 逆序数还原
    vs项目中使用c++调用lua
    多例模式
    关于O_APPEND模式write的原子性
    清醒
    编译时,遇到Couldn't build player because of unsupported data on target platform的解决方式
    把JavaScript和CSS放到外部文件里
    SSM框架——具体整合教程(Spring+SpringMVC+MyBatis)
    MMORPG网页游戏斩仙录全套源代码(服务端+client)
  • 原文地址:https://www.cnblogs.com/chjbbs/p/6365922.html
Copyright © 2011-2022 走看看