做家具的企业网站,投资小利润高的小生意,西安工商注册网上平台,亿诚建设项目管理有限公司网站原文BLOG#xff1a;http://iminmin.blog.51cto.com/689308/455992sudo”
是
Unix/Linux
平台上的一个非常有用的工具#xff0c;允许为非根用户赋予一些合理的
“
权利
”
#xff0c;让他们执行一些只有根用户或特许用户才能完成的任务#xff0c;从而减少根用户的登陆次…原文BLOGhttp://iminmin.blog.51cto.com/689308/455992sudo”
是
Unix/Linux
平台上的一个非常有用的工具允许为非根用户赋予一些合理的
“
权利
”
让他们执行一些只有根用户或特许用户才能完成的任务从而减少根用户的登陆次数和管理时间同时也提高了系统安全性。sudo的目的为非根用户授予根用户的权限配置文件/etc/sudoersvisudo命令编辑修改/etc/sudoers配置文件
1、一般用户赋权设置
[rootlocalhost ~]# visudo ……前面省略 69 ## Syntax: 70 ## 71 ## user MACHINECOMMANDS 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命令。用户执行命令效果[rootserver ~]# su - redhat [redhatserver ~]$ sudo /usr/sbin/useradd test //命令需要输入完整的路径 口令 //这里输入用户redhat自己的密码 [redhatserver ~]$ 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 UUUuser1,user2……
定义用户别名[rootlocalhost ~]# visudo ……前面省略 16 ## User Aliases 17 ## These arent 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 sudouseruser1,user2,user3,user4 //第一一个别名suduouser ……后面省略 69 ## Syntax: 70 ## 71 ## user MACHINECOMMANDS 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 命令行书写格式用户列用别名 ……后面省略 对于多个命令的设置[rootlocalhost ~]# 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 MACHINECOMMANDS 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 CCCcommand1,command2…… 定义命令别名对于多主机的设置和多登陆角色的设置•修改 Host_Alias HHHhost1,host2……定义主机别名修改后对应的命令行主机列位置也是用别名•Runas_Alias RRRrole1,role2…… 定义runas别名指定的是“目的用户”即sudo 允许转换至的用户建立相关别明后相关命令行相应的列也是用我们定义的别名。 2多个用户的设置同一群组用户[rootlocalhost ~]# visudo ……前面省略 81 82## Allows people in group wheel to run all commands 83# %wheel ALL(ALL) ALL //用户列%群组名 ……后面省略 END,希望大家能够合理为个用户账号授权。