LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Worried about the linux command not running in php (https://www.linuxquestions.org/questions/linux-newbie-8/worried-about-the-linux-command-not-running-in-php-809007/)

shreyansh 05-20-2010 01:43 AM

Worried about the linux command not running in php
 
hi all
i m newbie to this stuff
i am making network attached storage.
in that i cant do the following command
ifconfig eth0 192.168.1.1 netmask 255.255.255.0
/sbin/useradd username -p password
/etc/init.d/samba restart
/sbin/fdisk -l


i have put entry in sudoers file about apache users ALL but can not do this.
please help me if i m nt able to do the things then project is snatched away from me.


Thank you

ajeetsinghraina 05-20-2010 01:48 AM

Code:

please help me if i m nt able to do the things then project is snatched away from me.
Looks little weird...
Hope you save it through LQ.

Code:

i am making network attached storage.
Can you elaborate? What do you mean saying so?
Building your own NAS ????

Where are you trying to run this command?
which distribution?
what error it throws when you run those commands?

Code:

i have put entry in sudoers file about apache users ALL but can not do this.
please elaborate your need so that we can help you.

shreyansh 05-20-2010 02:14 AM

ok
listen
it is not throwing any error
simply i run
<?php
$output=shell_exec("/sbin/fdisk -l");
echo "$output";
?>
it will run fdisk command but in browser it display nothing.
same as others
i m using ubuntu 9.04
got something?

PMP 05-20-2010 02:24 AM

Are you able to execute some non privileged commnand say ls ?

Post the sudoers entry.

shreyansh 05-20-2010 02:32 AM

ya i can run ls and all that even also run ifconfig eth0 but while trying to change ip using it cant run.

here the sudoers file.
go to last line for apache users



Networking
Cmnd_Alias NETWORKING = /sbin/route, /sbin/ifconfig, /bin/ping, /sbin/dhclient, /usr/bin/net, /sbin/ipt$

## Installation and management of software
Cmnd_Alias SOFTWARE = /bin/rpm, /usr/bin/up2date, /usr/bin/yum

## Services
Cmnd_Alias SERVICES = /sbin/service, /sbin/chkconfig

## Updating the locate database
Cmnd_Alias LOCATE = /usr/bin/updatedb

## Storage
Cmnd_Alias STORAGE = /sbin/fdisk, /sbin/sfdisk, /sbin/parted, /sbin/partprobe, /bin/mount, /bin/umount

## Delegating permissions
Cmnd_Alias DELEGATING = /usr/sbin/visudo, /bin/chown, /bin/chmod, /bin/chgrp

## Processes
Cmnd_Alias PROCESSES = /bin/nice, /bin/kill, /usr/bin/kill, /usr/bin/killall

## Drivers
Cmnd_Alias DRIVERS = /sbin/modprobe

# Defaults specification

#
# Disable "ssh hostname sudo <cmd>", because it will show the password in clear.
# You have to run "ssh -t hostname sudo <cmd>".
#
Defaults requiretty

Defaults env_reset
Defaults env_keep = "COLORS DISPLAY HOSTNAME HISTSIZE INPUTRC KDEDIR \
LS_COLORS MAIL PS1 PS2 QTDIR USERNAME \
LANG LC_ADDRESS LC_CTYPE LC_COLLATE LC_IDENTIFICATION \
LC_MEASUREMENT LC_MESSAGES LC_MONETARY LC_NAME LC_NUMERIC \
LC_PAPER LC_TELEPHONE LC_TIME LC_ALL LANGUAGE LINGUAS \
## Next comes the main part: which users can run what software on
## which machines (the sudoers file can be shared between multiple
## systems).
## Syntax:
##
## user MACHINE=COMMANDS
##
## The COMMANDS section may have other options added to it.
##
## Allow root to run any commands anywhere

root ALL=(ALL) ALL

## Allows members of the 'sys' group to run networking, software,
## service management apps and more.
# %sys ALL = NETWORKING, SOFTWARE, SERVICES, STORAGE, DELEGATING, PROCESSES, LOCATE, DRIVERS

## Allows people in group wheel to run all commands
# %wheel ALL=(ALL) ALL

## Same thing without a password
# %wheel ALL=(ALL) NOPASSWD: ALL

## Allows members of the users group to mount and unmount the
## cdrom as root
# %users ALL=/sbin/mount /mnt/cdrom, /sbin/umount /mnt/cdrom

## Allows members of the users group to shutdown this system
%users localhost=/sbin/shutdown -h now
apache ALL=(ALL) ALL

PMP 05-20-2010 03:23 AM

If you are making sudo entry for any user you should invoke the command by preceding sudo to it.
Code:

sudo /sbin/fdisk -l

Secondly after you execute a command via sudo it asks for password, here in your case use should use NOPASSWD to do so


Code:

## Same thing without a password
# %wheel ALL=(ALL) NOPASSWD: ALL

Two check the how the things work try giving shell to apache user and the try executing this command after you switch to apache user.

shreyansh 05-20-2010 03:30 AM

i try that you say
su www-data
$ sudo /sbin/fdisk -l

prompt for password when i enter it will display nothing

$.
just

PMP 05-20-2010 03:46 AM

I can see an entry for "apache" in your sudoers and here you are switching to www-data ?
Which group this user www-data belongs to ?
And in case it belongs to apache you show change the sudoers to group permission

shreyansh 05-20-2010 03:49 AM

www-data:x:33:33:www-data:/var/www:/bin/sh
in /etc/passwd entry this code belongs
and this www-data is apache user i think.

PMP 05-20-2010 04:30 AM

Do you have any entry corresponding to apache in /etc/passwd.

If this is the apache user modify your /etc/soduer for this user not apache

shreyansh 05-20-2010 04:35 AM

no there is not any entry like apache user
just only www-data and what should i right for this in /etc/sudoers ?
that also called to change uid of www-data in /etc/passwd
if i change that it run all command but cant restart apache service and cant run php file in browser

PMP 05-20-2010 05:04 AM

add this entry in your /etc/sudoers and then try to execute the command oh this user shell

Code:

www-data ALL=(ALL) NOPASSWD: ALL

shreyansh 05-20-2010 05:14 AM

i put entry in sudoers

and try but get following error

$ sudo fdisk -l
sudo: must be setuid root
$ fdisk -l
$ /sbin/fdisk -l
when i set uid as root then commands are runnig but apache is not running.

moueza 05-20-2010 05:27 AM

set your $ account belonging to root group,as main group

shreyansh 05-20-2010 05:36 AM

i set adduser www-data root
Adding user `www-data' to group `root' ...
Adding user www-data to group root
Done.

now what to do?


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