Linux executes commands under root for PHP

Source: Internet
Author: User


Recently because of a PHP interface, but because of permissions problems, can not execute some specific commands, because PHP to run nobody.

Online search for some solutions, one is the use of the Su method, a C program to achieve, there is a super program to achieve.

Compared to the next, I think the Super command PHP calls more convenient, so this article mainly introduces the super simple implementation method.

First, download and install super, the process is as follows:

[root@ossec.cn ~] #wget ftp://ftp.ucolick.org/pub/users/will/super-3.30.0-tar.gz
[root@ossec.cn ~] #tar zxvf super-3.30.0-tar.gz
[root@ossec.cn ~] #cd super-3.30.0
[Root@ossec.cn Super-3.30.0]#./configure
[root@ossec.cn super-3.30.0] #make && make install
[root@ossec.cn ~] #super
Super
Super Version 3.30 Patchlevel 0
Commands available to User root (Use option '-h ' for a long-winded listing):

Command Name Comments
or pattern
———— ——–
When the installation is complete, the execution of super, as shown above, is verified to have been installed.

Second, the next configuration super (need to configure Super recognizable alias command)

[root@ossec.cn ~] #vi/usr/local/etc/super.tab
For example, if you want to invoke adduser with root privileges, add a line to the last line,
Auser/user/sbin/adduser Nobody,root

* First column is the command alias, the second column is the path to the calling command, and the third is the PHP startup username (the account that can do this), and the last one is any single user in the system *
If you also want to invoke other commands, you can install the above method to construct, of course, the first column alias can not be the same, such as
CPASS/USER/BIN/PASSWD Nobody,root

At this point, the configuration is complete.

Third, call

3.1, the use of super is:
super+ alias + other parameters (optional)
Cases:
[root@ossec.cn ~] #super auser Test
[root@ossec.cn ~] #super cpass Test
Change the password for user test.
New Password:
Invalid password: It is based on dictionary words
Re-enter the new password:
PASSWD: All authentication tokens have been successfully updated.

3.2, PHP calls the Super command:

Cases:
<?php system (' Super Auser test1′);?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.