In Linux, PHP runs the external command as root-sudo Implementation Method

Source: Internet
Author: User
In Linux, PHP runs the external command-sudo implementation method-Linux Enterprise Application-Linux server application information as root. The following is a detailed description. When I debugged the email server for a friend half a year ago, I found that super was not needed. I only needed sudo in Linux and did not dare to enjoy it exclusively. I put it on the forum,

Assume that the user running apache is nobody and the password is nobody2002.

To add, delete, and modify users in php

1> related files and paths:

/Etc/sudoers

/Usr/bin/sudo

/Usr/sbin/useradd

/Usr/sbin/userdel

/Usr/sbin/usermod

2> log on to the Linux system as the root user, modify the/etc/sudoers file, or run the command mongodo. Add the following line.

Nobody ALL = (ALL)/usr/sbin/useradd,/usr/sbin/userdel,/usr/sbin/usermod

# Note that the vi/etc/sudoers method cannot be used for modification.

3>

See the following procedure:


$ Sudo_path = "/usr/bin/sudo ";

$ Export _add = $ sudo_path. "/usr/sbin/useradd ";

$ Export _del = $ sudo_path. "/usr/sbin/userdel ";

$ Export _mod = $ sudo_path. "/usr/sbin/usermod ";

Function sudo_cmd ($ todo_cmd)

{

$ Userpass = "nobody2002 ";

$ Fp = @ popen ($ todo_cmd, "w ");

@ Fputs ($ fp, $ userpass );

@ Pclose ($ fp );

}

// Example:

$ User = "newuser ";

$ Pass = "12345 ";

$ Crypass = crypt ($ pass, "PK ");

// Add users

$ Cmd = $ pai_add. "-p $ crypass $ user ";

Sudo_cmd ($ cmd );

// Delete a user

$ Cmd = $ cmd_del. "$ user ";

Sudo_cmd ($ cmd );

// Modify the user (password, HOME Directory,..., pause, resume, etc)

$ Cmd = $ cmd_mod. "-p $ crypass $ user ";

Sudo_cmd ($ cmd );

$ Cmd = $ cmd_mod. "-L $ user ";

Sudo_cmd ($ cmd );

$ Cmd = $ cmd_mod. "-U $ user ";

Sudo_cmd ($ cmd );

?>

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.