歡迎您光臨本站 註冊首頁

Fedora (Redhat, RHEL)中使用sudo(轉載)

←手機掃碼閱讀     火星人 @ 2014-03-25 , reply:0

   源自:http://hi.baidu.com/yangyingchao ... f8108bd43f7cb2.html
   大家都知道,在Derbian和Ububtu中,為了安全起見,以普通用戶登錄以後在終端中不允許通過su命令來切換為超級用戶,想要代替超級用戶執行命令必須通過sudo命令來實現,
使用sudo命令確實比使用su更加安全。例如,在使用su的時候,由於本身屬於超級用戶,可以對任何文件進行任何操作,如果因為忘記自己以經成為了超級用戶、不小心刪除了某些系統所需的重要文件,將會引起及其嚴重的後果。而如果不使用su,則想執行某個命令,系統會自動檢察用戶是否擁有這個許可權,如果沒有,則提醒用戶,這個時候再使用sudo命令來暫時替代超級用戶來執行,則在這個過程中用戶最起碼會考慮一下操作是否正確,這樣在一定程度上可以防止因粗心而帶來的災難。
        但而在基於RedHat的Linux發行版(Fedora, RHEL, RedHat, 紅旗……)默認使用的是su,而非sudo,如果想要使用sudo,必須正確配置sudoers文件。sudoers位於/etc下,在使用sudo的時候,系統查詢sudoers裡面給用戶分配的許可權,然後根據查詢結果進行相關操作。下面這個文件是我從Fedora8的sudoers中拷貝出來的,然後進行了翻譯和整理,大家可以看一下,然後根據裡面的提示進行操作,正確配置自己機器的sudoers文件,打造一個更加安全的系統。


####################################################################
## 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 ofrelated commands, which can then be delegated out to particular usersor 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 ratherthan 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 thepassword 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 whichmachines (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並不難,只要修改這個文件相應的位置即可,文件裡面的用戶,組,以及相關命##令都可以根據自己的實際情況進行設定,這不難。但是如果一個伺服器上有很多的用戶,很多的組,如何去設定就要仔細推敲一下了



[ 本帖最後由 deepwhite 於 2007-11-27 15:50 編輯 ]
sudo.pdf

[火星人 ] Fedora (Redhat, RHEL)中使用sudo(轉載)已經有325次圍觀

http://coctec.com/docs/linux/show-post-168405.html