Need to give a non-privileged user permission to execute apachectl script

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
0
down vote

favorite












I want that a regular user to be able to execute apachectl in the system. And that would be the only thing that they can do outside of it normal permissions. What I did is to add this line at the bottom of the sudoers file:



sampleuser ALL=(root) NOEXEC:/usr/sbin/apachectl


So, as the user sampleuser, I executed apachectl command, and I get this error:



$ sudo apachectl stop 
[sudo] password for sampleuser:
/usr/sbin/apachectl: line 105: /usr/sbin/httpd: Permission denied


Now it seems like the permission is with the /usr/sbin/httpd command since apachectl script calls that executable file. So I added another line to the sudoers file:



sampleuser ALL=(root) NOEXEC:/usr/sbin/httpd


Now I executed the same command and I get the same error:



sudo apachectl start
[sudo] password for sampleuser:
/usr/sbin/apachectl: line 105: /usr/sbin/httpd: Permission denied


My question now, is that if there's a fix for this without having to edit the apachectl script file or another method that probably is easier than what I'm trying to do.



Thank you.







share|improve this question





















  • If I was to hazard a guess, it’s be that selinux doesn’t like a domain transition in there.
    – Jeff Schaller
    May 2 at 19:55










  • @JeffSchaller But selinux is not active. getenforce Disabled
    – VaTo
    May 2 at 20:02










  • Does ls -l /usr/sbin/httpd show root ownership and execute bits?
    – Jeff Schaller
    May 2 at 20:06










  • @JeffSchaller Yes -rwxr-xr-x 1 root root 545024 Sep 24 2017 /usr/sbin/httpd*
    – VaTo
    May 2 at 20:08














up vote
0
down vote

favorite












I want that a regular user to be able to execute apachectl in the system. And that would be the only thing that they can do outside of it normal permissions. What I did is to add this line at the bottom of the sudoers file:



sampleuser ALL=(root) NOEXEC:/usr/sbin/apachectl


So, as the user sampleuser, I executed apachectl command, and I get this error:



$ sudo apachectl stop 
[sudo] password for sampleuser:
/usr/sbin/apachectl: line 105: /usr/sbin/httpd: Permission denied


Now it seems like the permission is with the /usr/sbin/httpd command since apachectl script calls that executable file. So I added another line to the sudoers file:



sampleuser ALL=(root) NOEXEC:/usr/sbin/httpd


Now I executed the same command and I get the same error:



sudo apachectl start
[sudo] password for sampleuser:
/usr/sbin/apachectl: line 105: /usr/sbin/httpd: Permission denied


My question now, is that if there's a fix for this without having to edit the apachectl script file or another method that probably is easier than what I'm trying to do.



Thank you.







share|improve this question





















  • If I was to hazard a guess, it’s be that selinux doesn’t like a domain transition in there.
    – Jeff Schaller
    May 2 at 19:55










  • @JeffSchaller But selinux is not active. getenforce Disabled
    – VaTo
    May 2 at 20:02










  • Does ls -l /usr/sbin/httpd show root ownership and execute bits?
    – Jeff Schaller
    May 2 at 20:06










  • @JeffSchaller Yes -rwxr-xr-x 1 root root 545024 Sep 24 2017 /usr/sbin/httpd*
    – VaTo
    May 2 at 20:08












up vote
0
down vote

favorite









up vote
0
down vote

favorite











I want that a regular user to be able to execute apachectl in the system. And that would be the only thing that they can do outside of it normal permissions. What I did is to add this line at the bottom of the sudoers file:



sampleuser ALL=(root) NOEXEC:/usr/sbin/apachectl


So, as the user sampleuser, I executed apachectl command, and I get this error:



$ sudo apachectl stop 
[sudo] password for sampleuser:
/usr/sbin/apachectl: line 105: /usr/sbin/httpd: Permission denied


Now it seems like the permission is with the /usr/sbin/httpd command since apachectl script calls that executable file. So I added another line to the sudoers file:



sampleuser ALL=(root) NOEXEC:/usr/sbin/httpd


Now I executed the same command and I get the same error:



sudo apachectl start
[sudo] password for sampleuser:
/usr/sbin/apachectl: line 105: /usr/sbin/httpd: Permission denied


My question now, is that if there's a fix for this without having to edit the apachectl script file or another method that probably is easier than what I'm trying to do.



Thank you.







share|improve this question













I want that a regular user to be able to execute apachectl in the system. And that would be the only thing that they can do outside of it normal permissions. What I did is to add this line at the bottom of the sudoers file:



sampleuser ALL=(root) NOEXEC:/usr/sbin/apachectl


So, as the user sampleuser, I executed apachectl command, and I get this error:



$ sudo apachectl stop 
[sudo] password for sampleuser:
/usr/sbin/apachectl: line 105: /usr/sbin/httpd: Permission denied


Now it seems like the permission is with the /usr/sbin/httpd command since apachectl script calls that executable file. So I added another line to the sudoers file:



sampleuser ALL=(root) NOEXEC:/usr/sbin/httpd


Now I executed the same command and I get the same error:



sudo apachectl start
[sudo] password for sampleuser:
/usr/sbin/apachectl: line 105: /usr/sbin/httpd: Permission denied


My question now, is that if there's a fix for this without having to edit the apachectl script file or another method that probably is easier than what I'm trying to do.



Thank you.









share|improve this question












share|improve this question




share|improve this question








edited May 2 at 22:40









Filipe Brandenburger

3,451621




3,451621









asked May 2 at 19:43









VaTo

1,8021632




1,8021632











  • If I was to hazard a guess, it’s be that selinux doesn’t like a domain transition in there.
    – Jeff Schaller
    May 2 at 19:55










  • @JeffSchaller But selinux is not active. getenforce Disabled
    – VaTo
    May 2 at 20:02










  • Does ls -l /usr/sbin/httpd show root ownership and execute bits?
    – Jeff Schaller
    May 2 at 20:06










  • @JeffSchaller Yes -rwxr-xr-x 1 root root 545024 Sep 24 2017 /usr/sbin/httpd*
    – VaTo
    May 2 at 20:08
















  • If I was to hazard a guess, it’s be that selinux doesn’t like a domain transition in there.
    – Jeff Schaller
    May 2 at 19:55










  • @JeffSchaller But selinux is not active. getenforce Disabled
    – VaTo
    May 2 at 20:02










  • Does ls -l /usr/sbin/httpd show root ownership and execute bits?
    – Jeff Schaller
    May 2 at 20:06










  • @JeffSchaller Yes -rwxr-xr-x 1 root root 545024 Sep 24 2017 /usr/sbin/httpd*
    – VaTo
    May 2 at 20:08















If I was to hazard a guess, it’s be that selinux doesn’t like a domain transition in there.
– Jeff Schaller
May 2 at 19:55




If I was to hazard a guess, it’s be that selinux doesn’t like a domain transition in there.
– Jeff Schaller
May 2 at 19:55












@JeffSchaller But selinux is not active. getenforce Disabled
– VaTo
May 2 at 20:02




@JeffSchaller But selinux is not active. getenforce Disabled
– VaTo
May 2 at 20:02












Does ls -l /usr/sbin/httpd show root ownership and execute bits?
– Jeff Schaller
May 2 at 20:06




Does ls -l /usr/sbin/httpd show root ownership and execute bits?
– Jeff Schaller
May 2 at 20:06












@JeffSchaller Yes -rwxr-xr-x 1 root root 545024 Sep 24 2017 /usr/sbin/httpd*
– VaTo
May 2 at 20:08




@JeffSchaller Yes -rwxr-xr-x 1 root root 545024 Sep 24 2017 /usr/sbin/httpd*
– VaTo
May 2 at 20:08










1 Answer
1






active

oldest

votes

















up vote
0
down vote













Apachectl does not know that it needs to use sudo to execute httpd



Try something like this:



APACHE_HTTPD='sudo -E /usr/sbin/httpd' sudo -E /usr/sbin/apachectl start

-E, --preserve-env
Indicates to the security policy that the user wishes to reserve their
existing environment variables. The security policy may eturn an error
if the user does not have permission to preserve the environment.


So you will force apache2ctl to use a different command to call httpd...






share|improve this answer























  • I get this error: sudo: sorry, you are not allowed to set the following environment variables: APACHE_HTTPD
    – VaTo
    May 2 at 20:04











  • Apachectl stop is already running under sudo though...
    – Jeff Schaller
    May 2 at 20:05










  • Yes, but it is just a script, when the script tries to call the subprocess httpd, the sudo will block it? I am not sure...
    – Luciano Andress Martini
    May 2 at 20:06











  • Is it perhaps possible to give the user access to that env variable?
    – VaTo
    May 2 at 20:07










  • Amazon Linux AMI release 2017.09 I think that's based on fedora ID_LIKE="rhel fedora"
    – VaTo
    May 2 at 20:09











Your Answer







StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);








 

draft saved


draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f441394%2fneed-to-give-a-non-privileged-user-permission-to-execute-apachectl-script%23new-answer', 'question_page');

);

Post as a guest






























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
0
down vote













Apachectl does not know that it needs to use sudo to execute httpd



Try something like this:



APACHE_HTTPD='sudo -E /usr/sbin/httpd' sudo -E /usr/sbin/apachectl start

-E, --preserve-env
Indicates to the security policy that the user wishes to reserve their
existing environment variables. The security policy may eturn an error
if the user does not have permission to preserve the environment.


So you will force apache2ctl to use a different command to call httpd...






share|improve this answer























  • I get this error: sudo: sorry, you are not allowed to set the following environment variables: APACHE_HTTPD
    – VaTo
    May 2 at 20:04











  • Apachectl stop is already running under sudo though...
    – Jeff Schaller
    May 2 at 20:05










  • Yes, but it is just a script, when the script tries to call the subprocess httpd, the sudo will block it? I am not sure...
    – Luciano Andress Martini
    May 2 at 20:06











  • Is it perhaps possible to give the user access to that env variable?
    – VaTo
    May 2 at 20:07










  • Amazon Linux AMI release 2017.09 I think that's based on fedora ID_LIKE="rhel fedora"
    – VaTo
    May 2 at 20:09















up vote
0
down vote













Apachectl does not know that it needs to use sudo to execute httpd



Try something like this:



APACHE_HTTPD='sudo -E /usr/sbin/httpd' sudo -E /usr/sbin/apachectl start

-E, --preserve-env
Indicates to the security policy that the user wishes to reserve their
existing environment variables. The security policy may eturn an error
if the user does not have permission to preserve the environment.


So you will force apache2ctl to use a different command to call httpd...






share|improve this answer























  • I get this error: sudo: sorry, you are not allowed to set the following environment variables: APACHE_HTTPD
    – VaTo
    May 2 at 20:04











  • Apachectl stop is already running under sudo though...
    – Jeff Schaller
    May 2 at 20:05










  • Yes, but it is just a script, when the script tries to call the subprocess httpd, the sudo will block it? I am not sure...
    – Luciano Andress Martini
    May 2 at 20:06











  • Is it perhaps possible to give the user access to that env variable?
    – VaTo
    May 2 at 20:07










  • Amazon Linux AMI release 2017.09 I think that's based on fedora ID_LIKE="rhel fedora"
    – VaTo
    May 2 at 20:09













up vote
0
down vote










up vote
0
down vote









Apachectl does not know that it needs to use sudo to execute httpd



Try something like this:



APACHE_HTTPD='sudo -E /usr/sbin/httpd' sudo -E /usr/sbin/apachectl start

-E, --preserve-env
Indicates to the security policy that the user wishes to reserve their
existing environment variables. The security policy may eturn an error
if the user does not have permission to preserve the environment.


So you will force apache2ctl to use a different command to call httpd...






share|improve this answer















Apachectl does not know that it needs to use sudo to execute httpd



Try something like this:



APACHE_HTTPD='sudo -E /usr/sbin/httpd' sudo -E /usr/sbin/apachectl start

-E, --preserve-env
Indicates to the security policy that the user wishes to reserve their
existing environment variables. The security policy may eturn an error
if the user does not have permission to preserve the environment.


So you will force apache2ctl to use a different command to call httpd...







share|improve this answer















share|improve this answer



share|improve this answer








edited May 2 at 20:16


























answered May 2 at 20:03









Luciano Andress Martini

2,628725




2,628725











  • I get this error: sudo: sorry, you are not allowed to set the following environment variables: APACHE_HTTPD
    – VaTo
    May 2 at 20:04











  • Apachectl stop is already running under sudo though...
    – Jeff Schaller
    May 2 at 20:05










  • Yes, but it is just a script, when the script tries to call the subprocess httpd, the sudo will block it? I am not sure...
    – Luciano Andress Martini
    May 2 at 20:06











  • Is it perhaps possible to give the user access to that env variable?
    – VaTo
    May 2 at 20:07










  • Amazon Linux AMI release 2017.09 I think that's based on fedora ID_LIKE="rhel fedora"
    – VaTo
    May 2 at 20:09

















  • I get this error: sudo: sorry, you are not allowed to set the following environment variables: APACHE_HTTPD
    – VaTo
    May 2 at 20:04











  • Apachectl stop is already running under sudo though...
    – Jeff Schaller
    May 2 at 20:05










  • Yes, but it is just a script, when the script tries to call the subprocess httpd, the sudo will block it? I am not sure...
    – Luciano Andress Martini
    May 2 at 20:06











  • Is it perhaps possible to give the user access to that env variable?
    – VaTo
    May 2 at 20:07










  • Amazon Linux AMI release 2017.09 I think that's based on fedora ID_LIKE="rhel fedora"
    – VaTo
    May 2 at 20:09
















I get this error: sudo: sorry, you are not allowed to set the following environment variables: APACHE_HTTPD
– VaTo
May 2 at 20:04





I get this error: sudo: sorry, you are not allowed to set the following environment variables: APACHE_HTTPD
– VaTo
May 2 at 20:04













Apachectl stop is already running under sudo though...
– Jeff Schaller
May 2 at 20:05




Apachectl stop is already running under sudo though...
– Jeff Schaller
May 2 at 20:05












Yes, but it is just a script, when the script tries to call the subprocess httpd, the sudo will block it? I am not sure...
– Luciano Andress Martini
May 2 at 20:06





Yes, but it is just a script, when the script tries to call the subprocess httpd, the sudo will block it? I am not sure...
– Luciano Andress Martini
May 2 at 20:06













Is it perhaps possible to give the user access to that env variable?
– VaTo
May 2 at 20:07




Is it perhaps possible to give the user access to that env variable?
– VaTo
May 2 at 20:07












Amazon Linux AMI release 2017.09 I think that's based on fedora ID_LIKE="rhel fedora"
– VaTo
May 2 at 20:09





Amazon Linux AMI release 2017.09 I think that's based on fedora ID_LIKE="rhel fedora"
– VaTo
May 2 at 20:09













 

draft saved


draft discarded


























 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f441394%2fneed-to-give-a-non-privileged-user-permission-to-execute-apachectl-script%23new-answer', 'question_page');

);

Post as a guest













































































Popular posts from this blog

How to check contact read email or not when send email to Individual?

Bahrain

Postfix configuration issue with fips on centos 7; mailgun relay