[英]Run root script with Telegram Bot
I have a WebHook configured to commuticate with Telegram Bot, and I want to run some root commands when bot command arrives. 我有一个配置为与Telegram Bot通信的WebHook,并且我想在bot命令到达时运行一些root命令。 As we know the Telegram Bot sends https request to our web hook, so I can only run shell script as www-data user. 众所周知,Telegram Bot将https请求发送到我们的Web挂钩,所以我只能以www-data用户身份运行shell脚本。 But I actually want to run it as root. 但是我实际上想以root身份运行它。
My script kill.sh: 我的脚本kill.sh:
#!/bin/bash
kill -9 $1
From php I run: 从php我运行:
exec('kill.sh ' . $pidFromTelegramMessage);
Rights: 权利:
$ ls -al kill.sh
-r-xr-x--- 1 root www-data 24 Dec 16 15:27 kill.sh*
I even tried to put this script in /tmp directory but i does not work either. 我什至试图将此脚本放在/ tmp目录中,但我也不工作。 A always gets: 总会得到:
/tmp/kill.sh: 3: kill: Operation not permitted /tmp/kill.sh:3:杀死:不允许进行操作
I found only one way to do this. 我发现只有一种方法可以做到这一点。 I put this line into /etc/sudoers by run visudo command: 我通过运行visudo命令将此行放入/ etc / sudoers中 :
www-data ALL = NOPASSWD: /bin/kill, /usr/bin/tail, /tmp/run.sh
Add execute permissions to /tmp/run.sh: 将执行权限添加到/tmp/run.sh:
chmod a+x /tmp/run.sh
Now you can run these three commands as www-data user: 现在,您可以以www-data用户身份运行以下三个命令:
sudo kill -9 32233
sudo /tmp/run.sh
But you must think twice before allow anyone execute /tmp/run.sh script. 但是,在允许任何人执行/tmp/run.sh脚本之前,您必须三思。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.