Use PHP script to modify Linux or Unix system passwords

Source: Internet
Author: User
Tags php script linux

This article describes how to use a PHP script to modify a Linux or Unix system password

Required Tools and Installation:

You must install the following tools and software:

– The shell script that modifies the password

–sudo access Rights

–apache or LIGHTTPD Web server

–php Service-side program

Step #: Install shell scripts that can modify user passwords

This script can actually be used to modify the password of the Linux user (already tested in Linux and FreeBSD).

Example: Shell scripting code

#!/bin/sh
# \
exec expect -f “$0″ ${1+”$@”}
set password [lindex $argv 1]
spawn passwd [lindex $argv 0]
sleep 1
expect “assword:”
send “$password\r”
expect “assword:”
send “$password\r”
expect eof

Run shell script (download link)

$ chpasswd Username Password

Download the script and copy it to your Web root or to another location on your Web server (user readable):

$ CP chpasswd/var/www/

Or, if you use the LIGHTTPD Web server:

$ CP CHPASSWD/HOME/LIGHTTPD

Step: Execute command as root through sudo

The Apache or LIGHTTPD Web server will immediately use non-root permissions when it enters the background. This is a good way to prevent password changes, just as the passwd command requires root permission to modify the password of other user accounts.

Typically, Apache 2 uses www-data users, lighttpd use LIGHTTPD users (both regular users, not root users). Log in using the root user, and then execute the following command:

# Visudo

Your Web server now allows you to execute a password modification script (CHPASSWD). If you use the Apache Web server, execute the following command:

Www-data all=nopasswd:/var/www/chpasswd

Alternatively, if you use the LIGHTTPD Web server, execute the following command:

httpd all=nopasswd:/home/lighttpd/chpasswd

Save and exit files.

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.