2011-10-07 106 views
0

我想要做的是:編寫能夠以root身份運行/ sudo的一個Linux腳本

  • 編寫一個腳本來使用yum安裝一些軟件:百勝安裝任何
  • 這個腳本會被執行一個沒有root權限或sudo權限的用戶

我不反對在腳本中放入root密碼,我只是不知道該怎麼做,我的意思是我的腳本可能看起來像這樣:

sudo -u root -p password 
yum install whatever 

第一行是我不知道自己在做什麼,我理解將根證書放在這裏所涉及的安全風險,但對此不重要。

回答

5

The full power is described here

須藤的靈活性是廣泛估計下。這導致很差的做法(如sudo su - canon-ball手術方法)。

一個更好的方法是specificly允許你打算讓無需使用密碼的命令:

phill = NOPASSWD: /bin/ls, /usr/bin/lprm 

您可以選擇從特定的主機特定用戶運行做到這一點作爲特定的管理用戶。您甚至可以阻止用戶將shell轉義作爲參數傳遞。你可以讓sudo阻止啓動的程序動態執行更多的應用程序等等。你會想要read the man-page for sudoers (and be sure to read the procedures for editing this special file!)

這裏是事小情趣,(from here):

User_Alias  OPERATORS = joe, mike, jude 
Runas_Alias OP = root, operator 
Host_Alias  OFNET = 10.1.2.0/255.255.255.0 
Cmnd_Alias  PRINTING = /usr/sbin/lpc, /usr/bin/lprm 

OPERATORS ALL=ALL 
#The users in the OPERATORS group can run any command from any terminal. 

linus ALL=(OP) ALL 
# The user linus can run any command from any terminal as any user in the OP group (root or operator). 

user2 OFNET=(ALL) ALL 
# user user2 may run any command from any machine in the OFNET network, as any user. 

user3 ALL= PRINTING 
# user user3 may run lpc and lprm from any machine. 

go2linux ALL=(ALL) ALL 
# user go2linux may run any command from any machine acting as any user. (like Ubuntu) 

If you want not to be asked for a password use this form 
go2linux ALL=(ALL) ALL NO PASSWD: ALL 
0

如果用戶沒有隱藏sudo權限,那麼調用sudo是相當無用的,因爲它只會拒絕訪問。另外:使用sudo的用戶將而不是被要求輸入root密碼,但要輸入他自己的密碼。

相關問題