How can I modify the Linux password? what can I do if I forget the Linux password! How can I change the Linux password in linuxPHP? & nbsp
The Linux system password has been forgotten. how can I modify it!
Linux PHP password modification
------ Solution --------------------
Use a PHP script to modify the password of a Linux or Unix system.
Preparations
-Shell script for password modification;
-Sudo access;
-Apache or Lighttpd web server;
-PHP server program.
Step 1: Install a shell script that can change the user password
This script can be used to modify the password of a Linux user (tested in Linux and FreeBSD ).
Example: shell script code
#! /Bin/sh # \ exec expect CT-f "$0" ${1 + "$ @"} set password [lindex $ argv 1] spawn passwd [lindex $ argv 0] sleep 1 CT "assword: "send" $ password \ r "your CT" assword: "send" $ password \ r "your Ct eof to run the shell script (download link ):
$ Chpasswd username password download the script and copy it to your web root directory or other locations on the web server (readable ):
$ Cp chpasswd/var/www/or, if you use the Lighttpd web server:
$ Cp chpasswd/home/lighttpd Step 2: run the command as root through sudo
The Apache or Lighttpd web server immediately uses non-root permissions after it enters the background for running. This prevents password modification, just as the passwd command requires the root permission to modify the passwords of other user accounts.
Generally, Apache 2 uses www-data users and Lighttpd uses lighttpd users (both common and non-root users ). Log on as the root user and run the following command:
# Mongodo now your web server allows you to execute a chpasswd script ). If you use the Apache web server, run the following command:
Www-data ALL = NOPASSWD:/var/www/chpasswd or, if you use the Lighttpd web server, run the following command:
Httpd ALL = NOPASSWD:/home/lighttpd/chpasswd save and exit the file.
Step 3. create a PHP-based interface
Now you need to write a php script. There is a php script instance. You can modify it as needed. At least you need to correctly set the shell script location. Open the php script and find the shellscript line:
$ Shellscript = "sudo/home/lighttpd/chpasswd"; modify shellscript to the correct position. Download the PHP source code from here:
Step 4: run the script
Enter the address in the address bar of your web browser. you will see the username and password prompt:
If the password is successfully modified, you will receive a confirmation prompt:
Step 5: Security
1. never run the above script directly through the http protocol. Instead, use the https protocol.
2. put the script in a password-protected directory.
3. never trust users' input.
The above php script is just an example. In a real production environment, you need to consider using more powerful user input validation. Article reprinted from http://www.php0731.cn/index.php? Article-show.html & id = 1540 if you need to reprint please note
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.