![](/img/trans.png)
[英]Run a script from root and it calls another script that was in the sudo oracle. how to do that without asking the password of the oracle
[英]How to run script as another user without password?
我有必須作為user2運行的script.sh。 但是,此腳本只能在我的應用程序的user1下運行。
我想運行以下命令:
su user2 -C script.sh
但無需密碼即可運行。
我也希望這是非常嚴格的限制,因為在user1中只能在user2下運行script.sh,而不能在其他任何情況下運行。
我已經嘗試過使用sudoers文件執行此操作,但經過數小時的嘗試,它才變得無窮無盡。
如果有人可以提供一個明確的示例說明如何完成此操作(而不是像使用sudoers這樣的通用方法),將不勝感激。
嘗試運行:
su -c "Your command right here" -s /bin/sh username
假定您具有以該用戶身份進行sudo的權限,這將以用戶名運行命令。
調用visudo
並添加以下內容:
user1 ALL=(user2) NOPASSWD: /home/user2/bin/test.sh
命令路徑必須是絕對的 ! 然后從user1
shell調用sudo -u user2 /home/user2/bin/test.sh
。 做完了
`su -c "Your command right here" -s /bin/sh username`
上面的命令是正確的,但是在Red Hat上,如果selinux強制執行,則它將不允許cron以其他用戶身份執行腳本。 例; execl: couldn't exec /bin/sh execl: Permission denied
我必須安裝setroubleshoot和setools並運行以下命令來允許它:
yum install setroubleshoot setools
sealert -a /var/log/audit/audit.log
grep crond /var/log/audit/audit.log | audit2allow -M mypol
semodule -i mypol.p
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.