LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Red Hat (https://www.linuxquestions.org/questions/red-hat-31/)
-   -   Can't run useradd command through php script in RHEL 7 (https://www.linuxquestions.org/questions/red-hat-31/can%27t-run-useradd-command-through-php-script-in-rhel-7-a-4175538902/)

mayank4aug 04-06-2015 07:16 AM

Can't run useradd command through php script in RHEL 7
 
I am making a college project which is on Web Hosting and I have made up a php page in which I have added useradd command. I have given root privileges to apache entered in /etc/sudoers file but it's still not working.
script
-----------------------
<?php>
$p="mayank";
$i=`sudo useradd $p`;
?>
------------------------

T3RM1NVT0R 04-06-2015 12:30 PM

Does apache user has got /usr/sbin/useradd in the search path, if not then you have to use to run the command as: sudo /usr/sbin/useradd. In sudoers file also specify full path to useradd to be used with sudo.

mayank4aug 04-06-2015 12:37 PM

my sudoers entry is like this..
apache ALL = (ALL) NOPASSWD:ALL

T3RM1NVT0R 04-06-2015 12:44 PM

You did not answer the other question I asked. Did you give full path for useradd in your php script? If not did you try giving full path? Did it work?

When you run su - apache and then run "which useradd" without quotes what do you get?

mayank4aug 04-07-2015 02:21 AM

Yes, I have appended the /usr/sbin/useradd path in sudoers like this.
apache ALL=NOPASSWD: /usr/sbin/useradd

but still not working.
when I run su - apache it says "This account is currently not available"

echo,touch commands are working through php but systemctl,useradd like are not working.

T3RM1NVT0R 04-07-2015 04:53 AM

You are using a service account. When it says this account is not available check in /etc/passwd and see if it set to /sbin/nologin or /bin/false. Not sure why you need apache account to do the password reset, you can link any other account in the backend to do that. It is not a good idea to provide shell access to service account, still you want to do it for testing purpose you can do but not at all advisable in production

mayank4aug 04-07-2015 05:16 AM

I want to make it for my college project.

-Ok I have added a user named mayank shell /bin/bash
-Entered path for mayank in sudoers
-Created a php script

<?php>
$p="mayank";
$i=`sudo useradd $p`;
?>

-still not working.

I have changed the user in httpd.conf as mayank

Same configuration works in RHEL 4 but not in RHEL 7.

GaWdLy 04-20-2015 01:54 AM

Selinux is enforcing in rhel 7 by default. That might require some tweaking.


All times are GMT -5. The time now is 12:16 AM.