A
A
Alexander Mekhonoshin2014-07-15 00:52:12
linux
Alexander Mekhonoshin, 2014-07-15 00:52:12

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

6 answer(s)
S
Sergey Savostin, 2014-07-15
@savostin

By cron as root, run a script that will check some flag (file, mysql, it doesn't matter), which will be set from web.

E
evnuh, 2014-07-15
@evnuh

sudoers?

D
Dmitry Entelis, 2014-07-15
@DmitriyEntelis

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.
Accordingly, it is necessary to configure visudo so that the user under which the web server is running has rights to sudo this script. And that's it, problem solved.

V
Vlad Zhivotnev, 2014-07-18
@inkvizitor68sl

Use sudo with NOPASSWD

S
Sergey, 2014-07-15
@butteff

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

M
metajiji, 2015-01-07
@metajiji

I’ll add another option with expect or empty to the piggy bank, if it’s very important to enter a password :)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question