<?xml version="1.0" encoding="UTF-8"?><rss
version="2.0"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
> <channel><title>Comments on: Change Linux or UNIX system password using PHP script</title> <atom:link href="http://www.cyberciti.biz/tips/change-linux-or-unix-system-password-using-php-script.html/feed" rel="self" type="application/rss+xml" /><link>http://www.cyberciti.biz/tips/change-linux-or-unix-system-password-using-php-script.html</link> <description>This is a Linux sys admin journal by Vivek about sys admin work, Linux tips &#38; tricks, hacks, news and more.</description> <lastBuildDate>Fri, 10 Feb 2012 20:37:43 +0000</lastBuildDate> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.3.1</generator> <item><title>By: rchilro</title><link>http://www.cyberciti.biz/tips/change-linux-or-unix-system-password-using-php-script.html#comment-173344</link> <dc:creator>rchilro</dc:creator> <pubDate>Wed, 17 Aug 2011 08:37:00 +0000</pubDate> <guid
isPermaLink="false">http://www.cyberciti.biz/tips/change-linux-or-unix-system-password-using-php-script.html#comment-173344</guid> <description>if I may suggest, you can replace the end of the script like this:
# send passwd command
send -- &quot;passwd $user\r&quot;
expect &quot;assword:&quot; {
send &quot;$password\r&quot;
expect  &quot;assword:&quot;
send &quot;$password\r&quot;
send &quot;\r&quot;
send &quot;exit\r&quot;
expect eof
} &quot;Unknown user&quot; {
send &quot;\r&quot;
send &quot;exit\r&quot;
expect eof
}
if expect doesnt find the password, it will change to the unknown user statement and exit... you can treat the log later.
another suggestion would be to not allowing the webserver to have root and instead, save the command to a file and use chron to execute it later. this file can be outside the scope of webserver and you can block root change, etc.</description> <content:encoded><![CDATA[<p>if I may suggest, you can replace the end of the script like this:</p><p># send passwd command<br
/> send &#8212; &#8220;passwd $user\r&#8221;<br
/> expect &#8220;assword:&#8221; {<br
/> send &#8220;$password\r&#8221;<br
/> expect  &#8220;assword:&#8221;<br
/> send &#8220;$password\r&#8221;<br
/> send &#8220;\r&#8221;<br
/> send &#8220;exit\r&#8221;<br
/> expect eof<br
/> } &#8220;Unknown user&#8221; {<br
/> send &#8220;\r&#8221;<br
/> send &#8220;exit\r&#8221;<br
/> expect eof<br
/> }<br
/> if expect doesnt find the password, it will change to the unknown user statement and exit&#8230; you can treat the log later.</p><p>another suggestion would be to not allowing the webserver to have root and instead, save the command to a file and use chron to execute it later. this file can be outside the scope of webserver and you can block root change, etc.</p> ]]></content:encoded> </item> <item><title>By: karthik</title><link>http://www.cyberciti.biz/tips/change-linux-or-unix-system-password-using-php-script.html#comment-171766</link> <dc:creator>karthik</dc:creator> <pubDate>Mon, 06 Jun 2011 12:13:36 +0000</pubDate> <guid
isPermaLink="false">http://www.cyberciti.biz/tips/change-linux-or-unix-system-password-using-php-script.html#comment-171766</guid> <description>Hi
i am getting the below error when i tested the script in command line.
i have chmod 755 chpasswd.sh
error message .....
exec: 3: expect: not found
Kindly advice</description> <content:encoded><![CDATA[<p>Hi<br
/> i am getting the below error when i tested the script in command line.<br
/> i have chmod 755 chpasswd.sh<br
/> error message &#8230;..<br
/> exec: 3: expect: not found<br
/> Kindly advice</p> ]]></content:encoded> </item> <item><title>By: Akash</title><link>http://www.cyberciti.biz/tips/change-linux-or-unix-system-password-using-php-script.html#comment-157723</link> <dc:creator>Akash</dc:creator> <pubDate>Sun, 11 Jul 2010 15:36:19 +0000</pubDate> <guid
isPermaLink="false">http://www.cyberciti.biz/tips/change-linux-or-unix-system-password-using-php-script.html#comment-157723</guid> <description>Hi; i m having problem with my php installation in linux on my pc. Whenever i try to start the service of php, it throws an error &quot;service failed&quot;. but it installs without any error if I connect my hard disk to someone else&#039;s computer. can anyone has solution for this problem?????</description> <content:encoded><![CDATA[<p>Hi; i m having problem with my php installation in linux on my pc. Whenever i try to start the service of php, it throws an error &#8220;service failed&#8221;. but it installs without any error if I connect my hard disk to someone else&#8217;s computer. can anyone has solution for this problem?????</p> ]]></content:encoded> </item> <item><title>By: Ashish</title><link>http://www.cyberciti.biz/tips/change-linux-or-unix-system-password-using-php-script.html#comment-156224</link> <dc:creator>Ashish</dc:creator> <pubDate>Thu, 27 May 2010 13:23:40 +0000</pubDate> <guid
isPermaLink="false">http://www.cyberciti.biz/tips/change-linux-or-unix-system-password-using-php-script.html#comment-156224</guid> <description>Hi;
Thanks for this script. It worked for me on Solaris 10.
regards;
Ashish</description> <content:encoded><![CDATA[<p>Hi;</p><p>Thanks for this script. It worked for me on Solaris 10.</p><p>regards;<br
/> Ashish</p> ]]></content:encoded> </item> <item><title>By: Thuan VU DUC</title><link>http://www.cyberciti.biz/tips/change-linux-or-unix-system-password-using-php-script.html#comment-155751</link> <dc:creator>Thuan VU DUC</dc:creator> <pubDate>Wed, 05 May 2010 18:33:26 +0000</pubDate> <guid
isPermaLink="false">http://www.cyberciti.biz/tips/change-linux-or-unix-system-password-using-php-script.html#comment-155751</guid> <description>Have you try grant execution for the file chpasswd?
chmod +x /var/www/chpasswd
Hope thís help.</description> <content:encoded><![CDATA[<p>Have you try grant execution for the file chpasswd?<br
/> chmod +x /var/www/chpasswd<br
/> Hope thís help.</p> ]]></content:encoded> </item> <item><title>By: an0nym0us</title><link>http://www.cyberciti.biz/tips/change-linux-or-unix-system-password-using-php-script.html#comment-155419</link> <dc:creator>an0nym0us</dc:creator> <pubDate>Mon, 26 Apr 2010 21:31:36 +0000</pubDate> <guid
isPermaLink="false">http://www.cyberciti.biz/tips/change-linux-or-unix-system-password-using-php-script.html#comment-155419</guid> <description>@Terry
That&#039;s a nice little function but it looks like it only works for users who have shell access. For instance, it looks like it won&#039;t work for users with /sbin/nologin as a shell, such as is typical for FTP users.</description> <content:encoded><![CDATA[<p>@Terry</p><p>That&#8217;s a nice little function but it looks like it only works for users who have shell access. For instance, it looks like it won&#8217;t work for users with /sbin/nologin as a shell, such as is typical for FTP users.</p> ]]></content:encoded> </item> <item><title>By: an0nym0us</title><link>http://www.cyberciti.biz/tips/change-linux-or-unix-system-password-using-php-script.html#comment-155417</link> <dc:creator>an0nym0us</dc:creator> <pubDate>Mon, 26 Apr 2010 20:48:21 +0000</pubDate> <guid
isPermaLink="false">http://www.cyberciti.biz/tips/change-linux-or-unix-system-password-using-php-script.html#comment-155417</guid> <description>Thank you.
One note for CentOS/RHEL users is that &#039;requiretty&#039; is enabled by default in the sudoers file.  To get around this add:
Defaults:www-data  !requiretty
before the &quot;www-data ALL=NOPASSWD: /var/www/chpasswd&quot; line.  Obviously you&#039;ll need substitute the name of the user that the webserver runs under if it isn&#039;t www-data (in CentOS it seems to be &#039;apache&#039; by default).
Thanks again!</description> <content:encoded><![CDATA[<p>Thank you.</p><p>One note for CentOS/RHEL users is that &#8216;requiretty&#8217; is enabled by default in the sudoers file.  To get around this add:</p><p>Defaults:www-data  !requiretty</p><p>before the &#8220;www-data ALL=NOPASSWD: /var/www/chpasswd&#8221; line.  Obviously you&#8217;ll need substitute the name of the user that the webserver runs under if it isn&#8217;t www-data (in CentOS it seems to be &#8216;apache&#8217; by default).</p><p>Thanks again!</p> ]]></content:encoded> </item> <item><title>By: Aurangzeb</title><link>http://www.cyberciti.biz/tips/change-linux-or-unix-system-password-using-php-script.html#comment-153278</link> <dc:creator>Aurangzeb</dc:creator> <pubDate>Tue, 02 Feb 2010 09:51:27 +0000</pubDate> <guid
isPermaLink="false">http://www.cyberciti.biz/tips/change-linux-or-unix-system-password-using-php-script.html#comment-153278</guid> <description>A unix sofrware is copied and installed on another hard drive but during booting it is protected, how to unprotect?</description> <content:encoded><![CDATA[<p>A unix sofrware is copied and installed on another hard drive but during booting it is protected, how to unprotect?</p> ]]></content:encoded> </item> <item><title>By: tom</title><link>http://www.cyberciti.biz/tips/change-linux-or-unix-system-password-using-php-script.html#comment-152895</link> <dc:creator>tom</dc:creator> <pubDate>Wed, 13 Jan 2010 11:52:27 +0000</pubDate> <guid
isPermaLink="false">http://www.cyberciti.biz/tips/change-linux-or-unix-system-password-using-php-script.html#comment-152895</guid> <description>Apache error_log says password
any help ?</description> <content:encoded><![CDATA[<p>Apache error_log says password</p><p>any help ?</p> ]]></content:encoded> </item> <item><title>By: Edson Michel</title><link>http://www.cyberciti.biz/tips/change-linux-or-unix-system-password-using-php-script.html#comment-152585</link> <dc:creator>Edson Michel</dc:creator> <pubDate>Tue, 29 Dec 2009 20:39:43 +0000</pubDate> <guid
isPermaLink="false">http://www.cyberciti.biz/tips/change-linux-or-unix-system-password-using-php-script.html#comment-152585</guid> <description>Thanks a lot
Your script help a lot but I have to do more configuration in linux for run it.
the aditional configuration is
use command chown in the script!!!
and watch the error_log of httpd
thanks again</description> <content:encoded><![CDATA[<p>Thanks a lot<br
/> Your script help a lot but I have to do more configuration in linux for run it.<br
/> the aditional configuration is</p><p>use command chown in the script!!!<br
/> and watch the error_log of httpd</p><p>thanks again</p> ]]></content:encoded> </item> <item><title>By: Corey</title><link>http://www.cyberciti.biz/tips/change-linux-or-unix-system-password-using-php-script.html#comment-150407</link> <dc:creator>Corey</dc:creator> <pubDate>Fri, 28 Aug 2009 20:02:36 +0000</pubDate> <guid
isPermaLink="false">http://www.cyberciti.biz/tips/change-linux-or-unix-system-password-using-php-script.html#comment-150407</guid> <description>Has anyone thought about adding a secret question onto the php webpage?  That way, you could use this script as a backend password change once the user has answered the secret question properly.
With such a system in place, the user can change there own password.... using presetup authentication.
any ideas?</description> <content:encoded><![CDATA[<p>Has anyone thought about adding a secret question onto the php webpage?  That way, you could use this script as a backend password change once the user has answered the secret question properly.</p><p>With such a system in place, the user can change there own password&#8230;. using presetup authentication.</p><p>any ideas?</p> ]]></content:encoded> </item> <item><title>By: Simon</title><link>http://www.cyberciti.biz/tips/change-linux-or-unix-system-password-using-php-script.html#comment-150404</link> <dc:creator>Simon</dc:creator> <pubDate>Fri, 28 Aug 2009 15:07:26 +0000</pubDate> <guid
isPermaLink="false">http://www.cyberciti.biz/tips/change-linux-or-unix-system-password-using-php-script.html#comment-150404</guid> <description>Is there a way to get past the perceived risk of the script running as root ? i.e is there any way the script could be run as the connected user?</description> <content:encoded><![CDATA[<p>Is there a way to get past the perceived risk of the script running as root ? i.e is there any way the script could be run as the connected user?</p> ]]></content:encoded> </item> <item><title>By: Jason</title><link>http://www.cyberciti.biz/tips/change-linux-or-unix-system-password-using-php-script.html#comment-150357</link> <dc:creator>Jason</dc:creator> <pubDate>Tue, 25 Aug 2009 21:55:04 +0000</pubDate> <guid
isPermaLink="false">http://www.cyberciti.biz/tips/change-linux-or-unix-system-password-using-php-script.html#comment-150357</guid> <description>Set this up and it works but the PHP does not change to say that it has completed???</description> <content:encoded><![CDATA[<p>Set this up and it works but the PHP does not change to say that it has completed???</p> ]]></content:encoded> </item> <item><title>By: Derek</title><link>http://www.cyberciti.biz/tips/change-linux-or-unix-system-password-using-php-script.html#comment-148695</link> <dc:creator>Derek</dc:creator> <pubDate>Mon, 25 May 2009 21:45:36 +0000</pubDate> <guid
isPermaLink="false">http://www.cyberciti.biz/tips/change-linux-or-unix-system-password-using-php-script.html#comment-148695</guid> <description>Terry,
I&#039;ve worked on combining your changePassword function with the original script.  Unfortunately this expect script does not gracefully handle the case of a nonexistent user.  I get the user&#039;s typed-in password printed (in clear) in my http error_log:
send: spawn id exp16 not open
while executing
&quot;send &quot;xxx\r&quot;&quot; </description> <content:encoded><![CDATA[<p>Terry,</p><p>I&#8217;ve worked on combining your changePassword function with the original script.  Unfortunately this expect script does not gracefully handle the case of a nonexistent user.  I get the user&#8217;s typed-in password printed (in clear) in my http error_log:</p><p>send: spawn id exp16 not open<br
/> while executing<br
/> &#8220;send &#8220;xxx\r&#8221;"</p> ]]></content:encoded> </item> <item><title>By: Terry</title><link>http://www.cyberciti.biz/tips/change-linux-or-unix-system-password-using-php-script.html#comment-147044</link> <dc:creator>Terry</dc:creator> <pubDate>Wed, 04 Feb 2009 05:27:02 +0000</pubDate> <guid
isPermaLink="false">http://www.cyberciti.biz/tips/change-linux-or-unix-system-password-using-php-script.html#comment-147044</guid> <description>I&#039;ve written a function which doesn&#039;t need an external script, and does not need sudo access. This eliminated the concern of someone capturing the password by monitoring ps, and allows everything to be done without the need for external files. A log file is created during the password change procedure, though this does not contain any passwords, it&#039;s used to verify the password being successfully changed, and it&#039;s deleted on completion.
Note: you may need to modify the expect strings, depending on your systems password chat.
&lt;pre&gt;
function changePassword($user, $currpwd, $newpwd) {
// Open a handle to expect in write mode
$p = popen(&#039;/usr/bin/expect&#039;,&#039;w&#039;);
// Log conversation for verification
$log = &#039;/tmp/passwd_&#039; . $user . &#039;_&#039; . time();
$cmd .= &quot;log_file -a \&quot;$log\&quot;; &quot;;
// Spawn a shell as $user
$cmd .= &quot;spawn /bin/su $user; &quot;;
$cmd .= &quot;expect \&quot;Password:\&quot;; &quot;;
$cmd .= &quot;send \&quot;$currpwd\\r\&quot;; &quot;;
$cmd .= &quot;expect \&quot;$user@\&quot;; &quot;;
// Change the unix password
$cmd .= &quot;send \&quot;/usr/bin/passwd\\r\&quot;; &quot;;
$cmd .= &quot;expect \&quot;(current) UNIX password:\&quot;; &quot;;
$cmd .= &quot;send \&quot;$currpwd\\r\&quot;; &quot;;
$cmd .= &quot;expect \&quot;Enter new UNIX password:\&quot;; &quot;;
$cmd .= &quot;send \&quot;$newpwd\\r\&quot;; &quot;;
$cmd .= &quot;expect \&quot;Retype new UNIX password:\&quot;; &quot;;
$cmd .= &quot;send \&quot;$newpwd\\r\&quot;; &quot;;
$cmd .= &quot;expect \&quot;passwd: password updated successfully\&quot;; &quot;;
// Commit the command to expect &amp; close
fwrite($p, $cmd); pclose ($p);
// Read &amp; delete the log
$fp = fopen($log,r);
$output = fread($fp, 2048);
fclose($fp); unlink($log);
$output = explode(&quot;\n&quot;,$output);
return (trim($output[count($output)-2]) == &#039;passwd: password updated successfully&#039;) ? true : false;
}
&lt;/pre&gt;</description> <content:encoded><![CDATA[<p>I&#8217;ve written a function which doesn&#8217;t need an external script, and does not need sudo access. This eliminated the concern of someone capturing the password by monitoring ps, and allows everything to be done without the need for external files. A log file is created during the password change procedure, though this does not contain any passwords, it&#8217;s used to verify the password being successfully changed, and it&#8217;s deleted on completion.</p><p>Note: you may need to modify the expect strings, depending on your systems password chat.</p><pre>
function changePassword($user, $currpwd, $newpwd) {
	// Open a handle to expect in write mode
	$p = popen('/usr/bin/expect','w');
	// Log conversation for verification
	$log = '/tmp/passwd_' . $user . '_' . time();
	$cmd .= "log_file -a \"$log\"; ";
	// Spawn a shell as $user
	$cmd .= "spawn /bin/su $user; ";
	$cmd .= "expect \"Password:\"; ";
	$cmd .= "send \"$currpwd\\r\"; ";
	$cmd .= "expect \"$user@\"; ";
	// Change the unix password
	$cmd .= "send \"/usr/bin/passwd\\r\"; ";
	$cmd .= "expect \"(current) UNIX password:\"; ";
	$cmd .= "send \"$currpwd\\r\"; ";
	$cmd .= "expect \"Enter new UNIX password:\"; ";
	$cmd .= "send \"$newpwd\\r\"; ";
	$cmd .= "expect \"Retype new UNIX password:\"; ";
	$cmd .= "send \"$newpwd\\r\"; ";
	$cmd .= "expect \"passwd: password updated successfully\"; ";
	// Commit the command to expect &amp; close
	fwrite($p, $cmd); pclose ($p);
	// Read &amp; delete the log
	$fp = fopen($log,r);
	$output = fread($fp, 2048);
	fclose($fp); unlink($log);
	$output = explode("\n",$output);
	return (trim($output[count($output)-2]) == 'passwd: password updated successfully') ? true : false;
}
</pre>]]></content:encoded> </item> <item><title>By: Bollywood</title><link>http://www.cyberciti.biz/tips/change-linux-or-unix-system-password-using-php-script.html#comment-146939</link> <dc:creator>Bollywood</dc:creator> <pubDate>Tue, 27 Jan 2009 22:51:42 +0000</pubDate> <guid
isPermaLink="false">http://www.cyberciti.biz/tips/change-linux-or-unix-system-password-using-php-script.html#comment-146939</guid> <description>very help full article keep it up i like it because its full of details....</description> <content:encoded><![CDATA[<p>very help full article keep it up i like it because its full of details&#8230;.</p> ]]></content:encoded> </item> <item><title>By: vinotha</title><link>http://www.cyberciti.biz/tips/change-linux-or-unix-system-password-using-php-script.html#comment-145141</link> <dc:creator>vinotha</dc:creator> <pubDate>Mon, 29 Sep 2008 07:23:41 +0000</pubDate> <guid
isPermaLink="false">http://www.cyberciti.biz/tips/change-linux-or-unix-system-password-using-php-script.html#comment-145141</guid> <description>I try to execute chpasswd script to change password.
But the script didn’t change password successfully.
whn i use sh chpassword test test123 its working.
And I try to open the PHP file.
After I input username and password that also display error message.
=========
Password change failed
System returned following information…..:
Array
(
)
Please contact tech-support for more info! Or try
=========
in my /var/log/messages error shown as
authentication failure; logname= uid=0 euid=0 tty= ruser= rhost=  user=apache
What can I do to resolve this problem?</description> <content:encoded><![CDATA[<p>I try to execute chpasswd script to change password.<br
/> But the script didn’t change password successfully.</p><p>whn i use sh chpassword test test123 its working.</p><p>And I try to open the PHP file.<br
/> After I input username and password that also display error message.</p><p>=========<br
/> Password change failed<br
/> System returned following information…..:</p><p>Array<br
/> (<br
/> )</p><p>Please contact tech-support for more info! Or try</p><p>=========<br
/> in my /var/log/messages error shown as</p><p>authentication failure; logname= uid=0 euid=0 tty= ruser= rhost=  user=apache</p><p>What can I do to resolve this problem?</p> ]]></content:encoded> </item> <item><title>By: mangwantong</title><link>http://www.cyberciti.biz/tips/change-linux-or-unix-system-password-using-php-script.html#comment-144846</link> <dc:creator>mangwantong</dc:creator> <pubDate>Thu, 04 Sep 2008 03:15:19 +0000</pubDate> <guid
isPermaLink="false">http://www.cyberciti.biz/tips/change-linux-or-unix-system-password-using-php-script.html#comment-144846</guid> <description>If I use Solaris10 how can I do?
This code can run on solaris?</description> <content:encoded><![CDATA[<p>If I use Solaris10 how can I do?<br
/> This code can run on solaris?</p> ]]></content:encoded> </item> <item><title>By: dustro</title><link>http://www.cyberciti.biz/tips/change-linux-or-unix-system-password-using-php-script.html#comment-144802</link> <dc:creator>dustro</dc:creator> <pubDate>Sat, 30 Aug 2008 08:55:01 +0000</pubDate> <guid
isPermaLink="false">http://www.cyberciti.biz/tips/change-linux-or-unix-system-password-using-php-script.html#comment-144802</guid> <description>thanks for the code it works for me.</description> <content:encoded><![CDATA[<p>thanks for the code it works for me.</p> ]]></content:encoded> </item> <item><title>By: mangwantong</title><link>http://www.cyberciti.biz/tips/change-linux-or-unix-system-password-using-php-script.html#comment-144788</link> <dc:creator>mangwantong</dc:creator> <pubDate>Thu, 28 Aug 2008 08:28:31 +0000</pubDate> <guid
isPermaLink="false">http://www.cyberciti.biz/tips/change-linux-or-unix-system-password-using-php-script.html#comment-144788</guid> <description>Hi
After I try to run Step 1 I have some problem
password show change ok but not change realy
I try run below on my sytem
[root@localhost Code]# sh chpasswd admin mvc123
spawn passwd admin
Changing password for user admin.
New UNIX password: mvc123
Retype new UNIX password: mvc123
[root@localhost Code]#
That finish  I think it ok
I try to login by name = admin and newpass
login not ok but old password still work
I don&#039; know why?
my system ES3</description> <content:encoded><![CDATA[<p>Hi<br
/> After I try to run Step 1 I have some problem<br
/> password show change ok but not change realy</p><p>I try run below on my sytem<br
/> [root@localhost Code]# sh chpasswd admin mvc123<br
/> spawn passwd admin<br
/> Changing password for user admin.<br
/> New UNIX password: mvc123</p><p>Retype new UNIX password: mvc123</p><p>[root@localhost Code]#</p><p>That finish  I think it ok<br
/> I try to login by name = admin and newpass<br
/> login not ok but old password still work<br
/> I don&#8217; know why?</p><p>my system ES3</p> ]]></content:encoded> </item> </channel> </rss>
