简体   繁体   English

如何在没有密码的情况下从 php 脚本运行 sudo su?

[英]How to run sudo su from php script without password?

I am making a PHP script in which I have to send mail with attachment.我正在制作一个 PHP 脚本,我必须在其中发送带有附件的邮件。 I am using mutt and the command is...我正在使用 mutt,命令是...

echo 'This is the body' | mutt -s 'Testing mutt' 1nonlyabhishek002@gmail.com -a /home/jyoti/ab.txt 

...but the problem I am facing is that it works only with sudo su so I want to use sudo su in my PHP script without password. ...但我面临的问题是它只适用于sudo su所以我想在没有密码的 PHP 脚本中使用sudo su Please suggest me the way I can run sudo su in my PHP script.请建议我在 PHP 脚本中运行sudo su的方式。

I will be happy if there is way to run using password in script, that would be fine too.如果有办法在脚本中使用密码运行,我会很高兴,那也很好。 All I want is to execute the above command with sudo su with password or without password.我想要的只是使用带密码或不带密码的sudo su执行上述命令。 Security doesn't matter.安全无所谓。

Allow the web server user to run your script with no password, add to your sudoers file, in this example apache is the web server user:允许 web 服务器用户在没有密码的情况下运行你的脚本,添加到你的 sudoers 文件中,在这个例子中apache是 web 服务器用户:

apache ALL=NOPASSWD: /path/to/your/php/file.php 

You can use visudo to edit the sudoers file.您可以使用visudo来编辑 sudoers 文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM