本文介绍了如何从PHP运行在root用户bash脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何从PHP下运行bash脚本的 root用户(所有权限),而不是人用户 - ?PHP的默认用户
这就是sudo的visudo命令后,我的输出:
默认env_keep + =行列
默认env_keep + =LSCOLORS
默认env_keep + =SSH_AUTH_SOCK
默认env_keep + =TZ
默认env_keep + =DISPLAY XAUTHORIZATION XAUTHORITY
默认env_keep + =EDITOR VISUAL
默认env_keep + =HOME MAIL#用户特权规范
根ALL =(ALL)
%管理ALL =(ALL)
#取消,让人们在wheel组运行所有命令
#%轮ALL =(ALL)#没有密码同样的事情
#%轮ALL =(ALL)NOPASSWD:ALL#示例
#%的用户ALL = / sbin目录/安装/ CDROM,/ sbin目录/ umount / cdrom命令
#%的用户本地主机= / sbin目录/ shutdown -h now中
解决方案
您可以使用sudo:
执行exec(sudo的/你/脚本);
您应该允许无密码提示执行你的脚本。运行须藤visudo命令
控制台并添加以下字符串结尾:
人ALL = NOPASSWD:/你/脚本
您必须正确设置文件模式,以确保没有人可以修改此脚本,并把危险的内容进去(根控制台):
CHOWN根:根/你/脚本
行chmod 755 /你/脚本
How to run from PHP a bash script under root user (with all permissions) and not nobody user - php default user?
thats my output after sudo visudo:
Defaults env_keep += "LINES COLUMNS"
Defaults env_keep += "LSCOLORS"
Defaults env_keep += "SSH_AUTH_SOCK"
Defaults env_keep += "TZ"
Defaults env_keep += "DISPLAY XAUTHORIZATION XAUTHORITY"
Defaults env_keep += "EDITOR VISUAL"
Defaults env_keep += "HOME MAIL"
#User privilege specification
root ALL=(ALL) ALL
%admin ALL=(ALL) ALL
# Uncomment to allow people in group wheel to run all commands
# %wheel ALL=(ALL) ALL
# Same thing without a password
# %wheel ALL=(ALL) NOPASSWD: ALL
# Samples
# %users ALL=/sbin/mount /cdrom,/sbin/umount /cdrom
# %users localhost=/sbin/shutdown -h now
解决方案
You can use sudo:
exec("sudo /your/script");
You should allow executing your script without password prompt. Run sudo visudo
in console and add the following string to the end:
nobody ALL = NOPASSWD: /your/script
You must set up file mode properly to ensure that no one can modify this script and put dangerous contents into it (in root console):
chown root:root /your/script
chmod 755 /your/script
这篇关于如何从PHP运行在root用户bash脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!