[英]Write a linux script that can be run as root/sudo
我想做的是:
我不反對將root密碼放入腳本中,只是不知道該怎么做,我的意思是我的腳本可能如下所示:
sudo -u root -p password
yum install whatever
第一行是我不知道自己在做什么的地方,我了解將根憑據放入此處所涉及的安全風險,但這並不重要。
sudo的靈活性被廣泛低估。 這導致非常差的做法(例如sudo su -
規范球手術方法)。
更好的方法是明確允許您打算允許的命令, 而無需使用密碼 :
phill = NOPASSWD: /bin/ls, /usr/bin/lprm
您可以選擇對以特定管理員用戶身份運行的特定主機中的特定用戶執行此操作。 您甚至可以阻止用戶將shell轉義作為參數傳遞。 您可以使sudo阻止啟動的程序動態地執行其他應用程序等。您將需要閱讀sudoer的手冊頁(並務必閱讀編輯此特殊文件的過程!) 。
這里是一些小東西,( 從這里開始 ):
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
如果用戶不具有sudo權限,則調用sudo將非常無用,因為它只會拒絕訪問。 另外:使用sudo時, 不會要求用戶提供root密碼,而是要求其提供自己的密碼。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.