Chinaunix首页 | 论坛 | 博客
  • 博客访问: 92506478
  • 博文数量: 19283
  • 博客积分: 9968
  • 博客等级: 上将
  • 技术积分: 196062
  • 用 户 组: 普通用户
  • 注册时间: 2007-02-07 14:28
文章分类

全部博文(19283)

文章存档

2011年(1)

2009年(125)

2008年(19094)

2007年(63)

分类: LINUX

2008-03-28 23:04:15

 来源: 作者:Flindzvt 

大家都知道,在Derbian和Ububtu中,为了安全起见,以普通用户登录以后在终端中不允许通过su命令来切换为超级用户,想要代替超级用户执行命令必须通过sudo命令来实现,使用sudo命令确实比使用su更加安全。例如,在使用su的时候,由于本身属于超级用户,可以对任何文件进行任何操作,如果因为忘记自己以经成为了超级用户、不小心删除了某些系统所需的重要文件,将会引起及其严重的后果。而如果不使用su,则想执行某个命令,系统会自动检察用户是否拥有这个权限,如果没有,则提醒用户,这个时候再使用sudo命令来暂时替代超级用户来执行,则在这个过程中用户最起码会考虑一下操作是否正确,这样在一定程度上可以防止因粗心而带来的灾难。

但而在基于RedHat的Linux发行版(Fedora, RHEL, RedHat, 红旗……)默认使用的是su,而非sudo,如果想要使用sudo,必须正确配置sudoers文件。sudoers位于/etc下,在使用sudo的时候,系统查询sudoers里面给用户分配的权限,然后根据查询结果进行相关操作。下面这个文件是我从Fedora 8的sudoers中拷贝出来的,然后进行了翻译和整理,大家可以看一下,然后根据里面的提示进行操作,正确配置自己机器的sudoers文件,打造一个更加安全的系统。

QUOTE:
## Sudoers allows particular users to run various commands as the root user, without needing the root password.
## Sudoers 可以使特定的用户以根用户的身份执行各种命令,而无需根密码。

## Examples are provided at the bottom of the file for collections of related commands, which can then be delegated out to particular users or groups.
##文件的后面给出了相关指令集的例子,这些例子中的用户和组均可用特定的用户和组来代替(替换成你的系统里面的用户和组。)

## This file must be edited with the 'visudo' command.
## 这一文件必须使用visudo来进行编辑!!




## Host Aliases
## 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
# 机器的组,可以使用hostname或者IP地址来替代。




## 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 yyc = yyc
#用户入口,这通常并不是必需的,因为我们可以用正常组来替代,即:使用组名(groupname)而不是USERALIAS。




## 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/sbin/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



# Defaults specification(默认说明)

#
# Disable "ssh hostname sudo ", because it will show the password in clear. You have to run "ssh -t hostname sudo ".
#禁止在使用SSH登录的时候使用sudo,这样会显示明码。如果想要在SSH登录的时候使用sudo,登录时候必须使用ssh -t 来进行登录。
Defaults requiretty

Defaults env_reset
Defaults env_keep = "COLORS DISPLAY HOSTNAME HISTSIZE INPUTRC KDEDIR \
LS_COLORS MAIL PS1 PS2 QTDIR USERNAME \
LANG LC_ADDRESS LC_CTYPE LC_COLLATE LC_IDENTIFICATION \
LC_MEASUREMENT LC_MESSAGES LC_MONETARY LC_NAME LC_NUMERIC \
LC_PAPER LC_TELEPHONE LC_TIME LC_ALL LANGUAGE LINGUAS \
_XKB_CHARSET XAUTHORITY"

## Next comes the main part: which users can run what software on which machines (the sudoers file can be shared between multiple systems).
## 这一部分是重点,他规定了哪些用户可以在哪些机器上去运行哪些软件。注:不同的系统可以使用同一个sudoers文件。
## Syntax:
##
## user MACHINE=COMMANDS
##
## The COMMANDS section may have other options added to it.
##
## Allow root to run any commands anywhere (规定:根用户可以在任何系统上执行所有程序)
root ALL=(ALL) ALL

## Allows members of the 'sys' group to run networking, software, service management apps and more.使组sys里面的用户可以执行网络,软件,服务管理以及其他命令。
# %sys ALL = NETWORKING, SOFTWARE, SERVICES, STORAGE, DELEGATING, PROCESSES, LOCATE, DRIVERS
#将上面的注释去掉即可实现该功能,其中sys改为自己机器上的组即可。下同。

## Allows people in group wheel to run all commands(使组wheel里面的用户可以执行所有程序,但使用sudo的时候##需要输入个人密码。)
# %wheel ALL=(ALL) ALL

## Same thing without a password (同上,但是不需要输入密码,我的系统在这里进行了修改,使我可以直接使用sudo命令)
# %wheel ALL=(ALL) NOPASSWD: ALL
%yyc ALL=(ALL) NOPASSWD: ALL
## Allows members of the users group to mount and unmount the cdrom as root
#允许wheel组里面的用户执行mount 和umount。
# %users ALL=/sbin/mount /mnt/cdrom, /sbin/umount /mnt/cdrom

## Allows members of the users group to shutdown this system允许users里面的用户关闭系统。
# %users localhost=/sbin/shutdown -h now


其实,如果只是想在一个用户不多的机器上实现sudo并不难,只要修改这个文件相应的位置即可,文件里面的用户,组,以及相关命##令都可以根据自己的实际情况进行设定,这不难。但是如果一个服务器上有很多的用户,很多的组,如何去设定就要仔细推敲一下了。

阅读(420) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~