1. I wrote a php script to execute some shell scripts through the WEB interface. shell script will use sudo3.sudo user has set NOPASSWORD4. manually in the nobody user environment, (su-sbinbashnobody), and then execute shell script can be executed normally ,... 1. I wrote a php script to execute some shell scripts through the WEB interface.
2. sudo is used in shell scripts.
3. The sudo user has set NOPASSWORD
4. in the nobody user environment manually (su-s/bin/bash nobody), you can execute the shell script normally, but with php, The sudo statement will not be executed.
How can I use php for execution? Currently, the shell_exec function is used for execution.
Reply content:
1. I wrote a php script to execute some shell scripts through the WEB interface.
2. sudo is used in shell scripts.
3. The sudo user has set NOPASSWORD
4. in the nobody user environment manually (su-s/bin/bash nobody), you can execute the shell script normally, but with php, The sudo statement will not be executed.
How can I use php for execution? Currently, the shell_exec function is used for execution.
Yes, sudo: sorry, you must have a tty to run sudo
Modify the system configuration.
This is relatively dangerous .... First, no matter how it is implemented...
Sudo, you need sudo to enable the PHP process, so all php Execution is sudo.
Add www users to the root group
2. sudo is used in shell scripts.
This statement means that the execution of shell scripts requires the sudo permission?
It seems that this operation is very dangerous. Exercise caution.
Of course, not execution is generally caused by permission issues. Run the PHP script in the webserver environment. Take nginx as an example. Generally, www users are used. You can run the script in cli.root group
.
Second, it is easy to debug. You can try
sudo -Hu www php your.php
And,shell_exec
The function returns a value, which is the shell output,err_log()
Go to the file.
Php can only execute some commands, that is, use root.