Find the answer to your Linux question:
Results 1 to 8 of 8
Hi, I have a php script in which i am executing some shell commands (e.g date, who, ping, shutdown etc) using the System command. When I run the script from ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Feb 2007
    Posts
    6

    How to execute commands with root privileges from browser


    Hi,
    I have a php script in which i am executing some shell commands (e.g date, who, ping, shutdown etc) using the System command. When I run the script from command line, every thing goes fine because I have the root privileges.
    But if I run the script from web browser, only those commands are executed which don't need root privilages.
    It might be insecure but at the moment, I am not concerned about security.

    Regards,
    Atiq

  2. #2
    Just Joined! aliosa27's Avatar
    Join Date
    Jan 2007
    Posts
    10
    You can use sudo

  3. #3
    Linux Engineer d38dm8nw81k1ng's Avatar
    Join Date
    Mar 2005
    Location
    Newcastle
    Posts
    793
    Code:
    su -
    <password>
    then run your browser. some distros may limit the privelages you can use though (ubuntu places limits when using sudo)
    Here's why Linux is easier than Windows:
    Package Managers! Apt-Get and Portage (among others) allow users to install programs MUCH easier than Windows can.
    Hardware Drivers. In SuSE, ALL the hardware is detected and installed automatically! How is this harder than Windows' constant disc changing and rebooting?

  4. #4
    Linux Guru Cabhan's Avatar
    Join Date
    Jan 2005
    Location
    Seattle, WA, USA
    Posts
    3,252
    Depending on how your server is set up, this may not be true. Since PHP is a serverside language, your local permissions don't actually matter on the issue of commands run on the server from a PHP script. Further, due to these exact security concerns, the server is generally run as a VERY limited user.

    If you're hosting the script locally, you may be able to change the user who runs the script, but it's almost definitely not a good idea, especially not making the user root.

  5. #5
    Just Joined!
    Join Date
    Feb 2007
    Posts
    6
    Quote Originally Posted by Cabhan
    If you're hosting the script locally, you may be able to change the user who runs the script, but it's almost definitely not a good idea, especially not making the user root.
    Would you please explain, how can I do it? Any possible way to run such a script in browser?

    Atiq

  6. #6
    Just Joined!
    Join Date
    Feb 2007
    Posts
    6
    Quote Originally Posted by d38dm8nw81k1ng
    Code:
    su -
    <password>
    then run your browser. some distros may limit the privelages you can use though (ubuntu places limits when using sudo)
    Using sudo, I am able to run the script in command line but not in the browser.

  7. #7
    Linux Guru Cabhan's Avatar
    Join Date
    Jan 2005
    Location
    Seattle, WA, USA
    Posts
    3,252
    You could theoretically do it by changing what user the webserver runs as. This depends on which webserver you use: assuming it's Apache, you can probably find some documentation on it.

    Having said that, why do you want to be able to do this? Are you trying to access it from a remote location? Realize that changing the user that the webserver runs as changes who it runs as FOR EVERYTHING. Which means that any person in the world who manages to access your server runs anything they do as root.

    Why do you need it to run from a browser? Chances are there's a better way to do this.

  8. #8
    Just Joined!
    Join Date
    Feb 2007
    Posts
    6
    Well, I want to run a shell script but the input to the shell script is passed from the web browser. It gives an interactive password protected interface to network managers for remote bandwidth management.
    If I run an application locally as root which continuously listens from server, and send it messages from web server (apache) depending on different inputs to execute the shell script or the required commands. Do you think it is a good idea? I also need some hint to do it.
    Regards,
    Atiq

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •