Answer the question
In order to leave comments, you need to log in
How to restart nginx without root?
Or maybe go some other way.
I want to make a web interface for adding a site.
I really don't want to put the password in the `/var/www/` directory or give www-data special permissions.
But even doing `yes $PASSW | su root` will fail: `su: must be run from a terminal`.
There is an idea to wrap it with a utility that does keyboard emulation, but then you have to show the password, right?
Couldn't google anything useful.
Sincerely, Alexander.
Answer the question
In order to leave comments, you need to log in
By cron as root, run a script that will check some flag (file, mysql, it doesn't matter), which will be set from web.
The correct option is to set the rights of the user from which the script is executed, so that sudo on a specific command is performed without a password.
I am not an administrator, but I know that in CentOS this is solved by the visudo utility
, we use a script
#!/bin/sh
d=$1
if [ -f /etc/nginx/conf.d/$1.conf ];then
echo $d already exist
exit 1
fi
cat <<EOT >/etc/nginx/conf.d/$1.conf
server {
server_name www.$d;
return 301 http://$d\$uri;
}
server {
server_name $d;
set \$site_root '/www/$d';
root \$site_root;
include /etc/nginx/conf.d/common.inc;
location / {
include /etc/nginx/conf.d/common-loc.inc;
}
}
EOT
mkdir /www/$d
[ -f /www/$d/index.php ] || cat <<EOT >/www/$d/index.php
<? phpinfo(); ?>
EOT
service nginx reload
but we pull it from the console. 1. You can create a user, add it to /etc/sudoers/
2. Create a sh script, make this user the owner of the file.
3. Set the SUID for the script so that it runs on behalf of the owner
4. Run the sh script via ajax+php (exec function), of course, this is an option
About SUID and STICKY BIT
Or you can do without SUID, write it to /etc/sudoers www- data ALL = NOPASSWD: /home/script.sh
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question