[Ubuntu-PH] passwd in single command line

hard wyrd hardwyrd at gmail.com
Thu Sep 13 13:22:37 UTC 2007


Use the command 'chpasswd' to change passwords inline using a single line of
command. 'chpasswd' needs to run as root.

Syntax: chpasswd username:new_password   (ex. chpasswd user1:qwerty)

Here's a sample perl script that I am using to simply change a user's
password over the web. Make sure that the text boxes in the form where this
script will be called from (via method=post) uses the same names ('uname',
'upwd') or change to your own:

#!/usr/bin/perl
# Perl script to extract form input and execute command.
#
# Script by Romar Mayer Micabalo (c) 2007
# GPL v2. Distribute or use freely. Give credit where due.
#
# Read the standard input (sent by the form):

read(STDIN, $theForm, $ENV{'CONTENT_LENGTH'});

# Get the inputted values from the form

@valuepairs = split(/&/, $theForm);

# iterate within the values

foreach $pair (@valuepairs) {

           # Separate the name and value and change separator '+' to space,
and convert hex to ASCII:
           ($name, $value) = split(/=/, $pair);
           $value =~ tr/+/ /;
           $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;

# fill a new hash with the values

$FORM{$name} = $value;
}

# Check if chpasswd exists, or exit when missing.
open(CHPW, "|sudo /usr/sbin/chpasswd") || die "Could not open chpasswd or
chpasswd is missing: $!\n";

# Execute the password change
print CHPW "$FORM{'uname'}:$FORM{'upwd'}\n";

close(CHPW);

use CGI;
my $cgi = new CGI;
my $webcode = q(
<HTML>
<HEAD><TITLE>Password Change DONE!</TITLE></HEAD>
<BODY>
<h3>Done!</h3><br><br>
);

print $cgi->header(-type=>'text/html');
print $webcode;


This requires also to have the web server account to be added in the sudoers
list through 'visudo' then specify the exact file that will be executed
(/usr/sbin/chpasswd)


On 9/13/07, mac borje <mac.borje at gmail.com> wrote:
>
> hi everyone,
>
> Iam try to automate changing password on a curtain user on a ubuntu box
> coz passwd is a interactive program that will ask a password then ask again
> to retype. it is very helpful if some will tell me how to issue a single
> command to change password that will replaces the entry on the /etc/shadow
> coz i have a program the will grep that and inject on pearl script to have a
> deployment program for new password on the offline box.
>
> have a nice day
> ~mac
>
> --
> ubuntu-ph mailing list
> ubuntu-ph at lists.ubuntu.com
> https://lists.ubuntu.com/mailman/listinfo/ubuntu-ph
>
>


-- 
"A dog that has no bite, barks loudest."
Registered Linux User #400165
http://contour.runhosting.com - free host
http://baudizm.blogsome.com
http://phossil.ifastnet.com
Subscribed to:
LARTC, Open-ITLUG, PRUG, KLUG, linuxusersgroup, sybase.public.ase.linux

SHA256: 857dd62339c9fe27460b725747dfe25d5612933f7d879c35fb0cba2dadaf972f
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ubuntu.com/archives/ubuntu-ph/attachments/20070913/ec2116c7/attachment.html>


More information about the ubuntu-ph mailing list