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.