LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Red Hat
User Name
Password
Red Hat This forum is for the discussion of Red Hat Linux.

Notices


Reply
  Search this Thread
Old 04-06-2015, 07:16 AM   #1
mayank4aug
LQ Newbie
 
Registered: Jul 2014
Posts: 5

Rep: Reputation: Disabled
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`;
?>
------------------------

Last edited by mayank4aug; 04-06-2015 at 12:33 PM.
 
Old 04-06-2015, 12:30 PM   #2
T3RM1NVT0R
Senior Member
 
Registered: Dec 2010
Location: Internet
Distribution: Linux Mint, SLES, CentOS, Red Hat
Posts: 2,385

Rep: Reputation: 477Reputation: 477Reputation: 477Reputation: 477Reputation: 477
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.
 
Old 04-06-2015, 12:37 PM   #3
mayank4aug
LQ Newbie
 
Registered: Jul 2014
Posts: 5

Original Poster
Rep: Reputation: Disabled
my sudoers entry is like this..
apache ALL = (ALL) NOPASSWD:ALL
 
Old 04-06-2015, 12:44 PM   #4
T3RM1NVT0R
Senior Member
 
Registered: Dec 2010
Location: Internet
Distribution: Linux Mint, SLES, CentOS, Red Hat
Posts: 2,385

Rep: Reputation: 477Reputation: 477Reputation: 477Reputation: 477Reputation: 477
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?
 
Old 04-07-2015, 02:21 AM   #5
mayank4aug
LQ Newbie
 
Registered: Jul 2014
Posts: 5

Original Poster
Rep: Reputation: Disabled
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.
 
Old 04-07-2015, 04:53 AM   #6
T3RM1NVT0R
Senior Member
 
Registered: Dec 2010
Location: Internet
Distribution: Linux Mint, SLES, CentOS, Red Hat
Posts: 2,385

Rep: Reputation: 477Reputation: 477Reputation: 477Reputation: 477Reputation: 477
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
 
Old 04-07-2015, 05:16 AM   #7
mayank4aug
LQ Newbie
 
Registered: Jul 2014
Posts: 5

Original Poster
Rep: Reputation: Disabled
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.
 
Old 04-20-2015, 01:54 AM   #8
GaWdLy
Member
 
Registered: Feb 2013
Location: San Jose, CA
Distribution: RHEL/CentOS/Fedora
Posts: 457

Rep: Reputation: Disabled
Selinux is enforcing in rhel 7 by default. That might require some tweaking.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Restart FreeRadius from PHP Script (Run command as another user) buee Linux - Software 1 11-19-2018 04:01 AM
[SOLVED] how to run shell script command from php web page Ankush Seth Linux - Newbie 8 09-03-2013 10:35 AM
SSH into a windows PC and run a command from PHP script peterjfrancis Linux - Newbie 6 07-30-2009 12:10 PM
run php script from command line blizunt7 Programming 11 11-06-2008 11:59 AM
to run a html or php script with php5 command vincent_fr_60 Linux - Software 1 01-20-2006 06:41 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Red Hat

All times are GMT -5. The time now is 06:06 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration