2

I've been trying to grant www-data to use sudo service apache2 restart without a password but no matter what I try, nothing works. I have read a few hundred posts regarding this issue on different forums but nothing in them helps.

I know that the permissions are added in order, so the specific command should go at the end of the list. Here is my file:

#
# This file MUST be edited with the 'visudo' command as root.
#
# Please consider adding local content in /etc/sudoers.d/ instead of
# directly modifying this file.
#
# See the man page for details on how to write a sudoers file.
#
Defaults        env_reset
Defaults        secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"

# Host alias specification

# User alias specification

# Cmnd alias specification


# User privilege specification
root    ALL=(ALL) ALL

# Members of the admin group may gain root privileges
%admin ALL=(ALL) ALL

# Allow members of group sudo to execute any command
%sudo   ALL=(ALL) ALL

# See sudoers(5) for more information on "#include" directives:

# includedir /etc/sudoers.d

%www-data ALL=(ALL) NOPASSWD: /usr/sbin/service apache2 restart

From what I gather, anyone in www-data should now be able to run sudo service apache2 restart and not require a password. It still asks for a password. I have tried to add:

%www-data ALL=(ALL) NOPASSWD: ALL

And that works as expected. I can give them no password for all commands but not for one. Of course that would be really bad idea.

Any help would be appreciated. This is the latest version of Ubuntu

Anwar
  • 76,649
Deshiknaves
  • 81
  • 1
  • 1
  • 4

1 Answers1

6

Turns out I had sudo aliased in my .zshrc. Removing the alias fixed the issue. Now it works as it should.

This link was useful: Sudo arguments not working

Deshiknaves
  • 81
  • 1
  • 1
  • 4