Results 1 to 2 of 2

Thread: เพิ่ม Linux User ผ่าน shell_exec

  1. #1


    เพิ่ม Linux User ผ่าน shell_exec
    เรื่อง ssh authentication กับ php เพื่อใช้ useradd ในสิทธิ์ของ root
    :: linux ที่ผมใช้ connect ssh ไม่ผ่าน จึงเปลี่ยนไปใช้ shell_exec กับการจัดการ sudoers แทน

    <?php
    $host = "127.0.0.1" ;
    $output = shell_exec("ping -c1 $host");
    echo "<pre>$output</pre>";
    echo shell_exec(&#39;id&#39;
    $user = "hello";
    $pass = "wow";
    echo shell_exec("sudo -u root -S /usr/sbin/useradd $user");
    echo shell_exec("echo $pass |sudo -u root -S /usr/bin/passwd $user --stdin");
    echo shell_exec("id $user");
    ?>
    วิธีการจัดการแฟ้ม /etc/sudoers
    - เปลี่ยนสิทธิ์จาก 440 เป็น 777
    - เปิดแฟ้ม แล้วแก้ให้เลิกถามรหัสผ่านเมื่อใช้ sudo
    - เพิ่ม apache ALL= NOPASSWD: /usr/sbin/useradd, /usr/bin/passwd
    - ต้องเปลี่ยนกลับเป็น 0440 จึงจะสั่ง script ให้ทำงานได้
    - http://fr2.php.net/manual/en/function.shell-exec.php
    - http://www.gratisoft.us/sudo/man/sudoers.html
    ~: ทำทุกอย่างเพื่อ padawan :~

  2. #2
    Senior Member retool2's Avatar
    Join Date
    Aug 2008
    Location
    Under Relocation
    Posts
    178


    เวบอ้างอิงครับ

    http://www.perlphpasp.com/php/indexo.html

Similar Threads

  1. Replies: 0
    Last Post: 11-04-2008, 02:01 AM
  2. Replies: 0
    Last Post: 13-02-2008, 02:32 PM
  3. การย้าย user บน linux จากเครื่องหนึ่งไปอีกเครื่องหนึ่ง
    By ponglang in forum บทความ คอมพิวเตอร์ ทัวไป
    Replies: 0
    Last Post: 14-11-2007, 08:00 PM
  4. Replies: 0
    Last Post: 01-10-2007, 09:31 PM
  5. Replies: 0
    Last Post: 01-10-2007, 02:44 PM

Members who have read this thread : 0

Actions : (View-Readers)

There are no names to display.

Posting Permissions

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