Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1114076
  • 博文数量: 309
  • 博客积分: 6093
  • 博客等级: 准将
  • 技术积分: 3038
  • 用 户 组: 普通用户
  • 注册时间: 2008-02-03 17:14
个人简介

linux学习记录

文章分类

全部博文(309)

文章存档

2014年(2)

2012年(37)

2011年(41)

2010年(87)

2009年(54)

2008年(88)

分类:

2010-08-25 15:36:23

                     RHCE学习笔记

 

关于linux下面权限委派的讨论

 

权限委派介绍

linux系统中,管理员的权限非常的大,但是普通用户并没有什么权限,所以很有必要将权限分发给不同的普通用户,而且在linux下,权限的委派功能非常的强大,它可以基于命令集的权限委派。

 

所有的权限委派都在/etc/sudoers这个文件中定义。

/etc/sudoers这个文件也默认定义了很多权限委派。

我们可以参考这个文件来进行权限的委派

## User Aliases

## These aren't often necessary, as you can use regular groups

## (ie, from files, LDAP, NIS, etc) in this file - just use %groupname

## rather than USERALIAS

# User_Alias ADMINS = jsmith, mikem

这个是用户的别名,可以参考这模板来定义用户。

User_Alias ADMINS  =  user3,user4

在这里我们就定义了ADMINS等于user3 user4 这个两个普通用户。

下面我们就定义命令的别名

## Command Aliases

## These are groups of related commands...

 

## Networking

Cmnd_Alias NETWORKING = /sbin/route, /sbin/ifconfig, /bin/ping, /sbin/dhclient, /usr/bin/net, /sbin/iptables, /usr/bin/rfcomm, /usr/bin/wvdial, /sbin/iwconfig, /sbin/mii-tool

 

## Installation and management of software

Cmnd_Alias SOFTWARE = /bin/rpm, /usr/bin/up2date, /usr/bin/yum

 

## Services

Cmnd_Alias SERVICES = /sbin/service, /sbin/chkconfig

 

## Updating the locate database

Cmnd_Alias LOCATE = /usr/bin/updatedb

 

## Storage

Cmnd_Alias STORAGE = /sbin/fdisk, /sbin/sfdisk, /sbin/parted, /sbin/partprobe, /bin/mount, /bin/umount

 

## Delegating permissions

Cmnd_Alias DELEGATING = /usr/sbin/visudo, /bin/chown, /bin/chmod, /bin/chgrp

 

## Processes

Cmnd_Alias PROCESSES = /bin/nice, /bin/kill, /usr/bin/kill, /usr/bin/killall

 

## Drivers

Cmnd_Alias DRIVERS = /sbin/modprobe

这个就是系统中命令的别名,可以参考这个来定义命令的别名。

## USERS

Cmnd_Alias USERS = /usr/sbin/useradd, /usr/sbin/userdel, /usr/sbin/usermod

在这里我们就定义了命令的别名。

下面就开始引用。

##      user    MACHINE=COMMANDS

##

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

##

## Allow root to run any commands anywhere

root            ALL=(ALL)       ALL

ADMINS   ALL=(ALL)       USERS

在系统中,默认就有了root可以做任何事情,其实就是在这里定义的。

下面就是我们自己定义引用的,代表在ADMINS里面定义的用户可以做在USERS里面定义的命令。

下面我们来测试一下。

默认情况下,我们的普通用户是不可以添加用户的。

[root@localhost ~]#

[root@localhost ~]# su - user3

[user3@localhost ~]$

[user3@localhost ~]$ /usr/sbin/useradd user8

-bash: /usr/sbin/useradd: Permission denied

[user3@localhost ~]$

现在我们还是不可以添加用户,因为在user3的环境变量里什么没有这个命令的。我们必须用sudo的方式来执行命令,这个也就是sudo用法。

[user3@localhost ~]$

[user3@localhost ~]$ sudo /usr/sbin/useradd user8

 

We trust you have received the usual lecture from the local System

Administrator. It usually boils down to these three things:

 

    #1) Respect the privacy of others.

    #2) Think before you type.

    #3) With great power comes great responsibility.

 

Password:

[user3@localhost ~]$

[user3@localhost ~]$ id user8

uid=504(user8) gid=504(user8) groups=504(user8)

[user3@localhost ~]$

可以看到,这里它要我们输入一个密码,这个密码是自己的密码。

也是系统出于安全的考虑。

这样user8就添加成功了。

注意,在使用普通用户通过权限委派去执行命令的时候,一定要使用sudo去执行,还有执行的命令一定要是命令的绝对路径。

 

在linux下面权限委派的基本配置就到这里了。

阅读(659) | 评论(0) | 转发(0) |
0

上一篇:RHEL5.4文件ACL权限

下一篇:RHEL5.4用户管理

给主人留下些什么吧!~~