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 |
Code:
please help me if i m nt able to do the things then project is snatched away from me. Hope you save it through LQ. Code:
i am making network attached storage. 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. |
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? |
Are you able to execute some non privileged commnand say ls ?
Post the sudoers entry. |
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 |
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 |
i try that you say
su www-data $ sudo /sbin/fdisk -l prompt for password when i enter it will display nothing $. just |
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 |
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. |
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 |
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 |
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 |
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. |
set your $ account belonging to root group,as main group
|
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. |