【sudo】配置sudoers實現oracle使用者以root身份執行命令

murkey發表於2015-04-10
sudo命令可以實現在oracle使用者下以root使用者身份執行命令,這裡給出sudo命令的配置和使用方法。

1.美妙的
sudo命令存在價值
root使用者具有所有的操作許可權,是真正的“God”級別的使用者,這樣是非常危險的,sudo便是權利下放的途徑。
使用sudo,我們可以實現將root使用者一些特定的許可權定製後下放。

2.配置sudoers實現oracle使用者以root身份執行命令
我們可以透過配置/etc/sudoers檔案完成對sudo的配置。
其實,若想對sudo命令的進行完美配置相對比較複雜,其中包括別名定義和授權規則兩大類別,詳細的說明可以使用sudo的幫助頁進行檢視。不過我們若只是為了達到在oracle使用者下方便的以root使用者身份執行命令,相對是簡單的。這裡給出配置方法。
1)在root使用者下編輯sudoers配置檔案
如果不參考sudo命令的幫助頁,單純的從sudoers配置檔案中的註釋資訊中也可以獲得有效的調整提示。
[root@secdb1 ~]# vi /etc/sudoers
(1)修改前內容
# sudoers file.
#
# This file MUST be edited with the 'visudo' command as root.
#
# See the sudoers man page for the details on how to write a sudoers file.
#

# Host alias specification

# User alias specification

# Cmnd alias specification

# Defaults specification

# User privilege specification
root    ALL=(ALL) ALL

# Uncomment to allow people in group wheel to run all commands
#%wheel ALL=(ALL)       ALL

# Same thing without a password
#%wheel ALL=(ALL)       NOPASSWD: ALL

# Samples
# %users  ALL=/sbin/mount /cdrom,/sbin/umount /cdrom
# %users  localhost=/sbin/shutdown -h now

(2)變動內容是將與wheel組相關的配置資訊前的註釋符號“#”去掉。使所有屬於wheel組的使用者具有root使用者的所有命令執行的許可權。

(3)修改後內容
# sudoers file.
#
# This file MUST be edited with the 'visudo' command as root.
#
# See the sudoers man page for the details on how to write a sudoers file.
#

# Host alias specification

# User alias specification

# Cmnd alias specification

# Defaults specification

# User privilege specification
root    ALL=(ALL) ALL

# Uncomment to allow people in group wheel to run all commands
%wheel ALL=(ALL)       ALL

# Same thing without a password
%wheel ALL=(ALL)       NOPASSWD: ALL

# Samples
# %users  ALL=/sbin/mount /cdrom,/sbin/umount /cdrom
# %users  localhost=/sbin/shutdown -h now

2)將oracle使用者新增到wheel組中
[root@secdb1 ~]# vi /etc/group
在group檔案中找到“wheel”關鍵字所在行記錄。
在wheel記錄後面新增“,oracle”,實現將oracle使用者加入到wheel組中

修改前內容
wheel:x:10:root

修改後內容
wheel:x:10:root,oracle

到此,配置階段結束。此時oracle使用者可以透過sudo的方式執行root使用者下的所有命令。

3.測試oracle使用者下sudo的執行效果
我們可以使用“id”命令簡單測試一下sudo命令的可用性。
1)oracle使用者下使用id命令獲得當前使用者的資訊
[oracle@secdb1 ~]$ id
uid=500(oracle) gid=501(oinstall) groups=10(wheel),500(dba),501(oinstall) context=user_u:system_r:unconfined_t

2)使用sudo方式執行“id”命令
[oracle@secdb1 ~]$ sudo id
uid=0(root) gid=0(root) groups=0(root),1(bin),2(daemon),3(sys),4(adm),6(disk),10(wheel) context=root:system_r:unconfined_t

很顯然,此時的反饋資訊中記錄了root使用者的相關資訊,並且此處沒有提示輸入密碼。

4.小結
關於sudo的深入配置方法,請參考sudo的幫助頁(可以使用“man sudo”自行查詢)。本文給出的是在oracle使用者使用sudo命令快速簡便的配置方法。簡便帶來的結果是定製的不夠細緻,此時oracle使用者可以以root身份執行所有命令,沒有體現出sudo對許可權限制的真諦。

Good luck.

secooler
11.05.14

-- The End --

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/500314/viewspace-1562966/,如需轉載,請註明出處,否則將追究法律責任。

相關文章