From owner-freebsd-questions@FreeBSD.ORG Tue Jan 17 06:17:49 2006 Return-Path: X-Original-To: freebsd-questions@freebsd.org Delivered-To: freebsd-questions@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 7C6C816A41F for ; Tue, 17 Jan 2006 06:17:49 +0000 (GMT) (envelope-from youshi10@u.washington.edu) Received: from mxout4.cac.washington.edu (mxout4.cac.washington.edu [140.142.33.19]) by mx1.FreeBSD.org (Postfix) with ESMTP id 0E4D743D62 for ; Tue, 17 Jan 2006 06:17:43 +0000 (GMT) (envelope-from youshi10@u.washington.edu) Received: from smtp.washington.edu (smtp.washington.edu [140.142.33.9]) by mxout4.cac.washington.edu (8.13.5+UW05.10/8.13.5+UW05.09) with ESMTP id k0H6HgpD015315 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Mon, 16 Jan 2006 22:17:42 -0800 X-Auth-Received: from [192.168.0.21] (dsl254-013-145.sea1.dsl.speakeasy.net [216.254.13.145]) (authenticated authid=youshi10) by smtp.washington.edu (8.13.5+UW05.10/8.13.5+UW05.09) with ESMTP id k0H6HcU7031560 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NOT) for ; Mon, 16 Jan 2006 22:17:41 -0800 Message-ID: <43CC8C01.2020703@u.washington.edu> Date: Mon, 16 Jan 2006 22:17:37 -0800 From: Garrett Cooper User-Agent: Mail/News 1.5 (X11/20060113) MIME-Version: 1.0 To: freebsd-questions@freebsd.org References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Uwash-Spam: Gauge=IIIIIII, Probability=7%, Report='__CT 0, __CTE 0, __CT_TEXT_PLAIN 0, __HAS_MSGID 0, __MIME_TEXT_ONLY 0, __MIME_VERSION 0, __SANE_MSGID 0, __USER_AGENT 0' Subject: Re: how do I (non-interactively) change a users password in a script ? X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 17 Jan 2006 06:17:49 -0000 user wrote: > /bin/sh script. > > Need to change a users password within the script based on a file of > user/pass I am feeding the script. > > Easy. > > Except the passwd command does not seem to be able to take a password as > an argument - I don't think that the passwd command can run > non-interactively. > > So how is this done ? It looks like the adduser script does it > non-interactively somehow ... but I don't see how. > > Thanks. > Yes, you can do this: -h fd This option provides a special interface by which interac- tive scripts can set an account password using pw. Because the command line and environment are fundamentally insecure mechanisms by which programs can accept information, pw will only allow setting of account and group passwords via a file descriptor (usually a pipe between an interactive script and the program). sh, bash, ksh and perl all pos- sess mechanisms by which this can be done. Alternatively, pw will prompt for the user's password if -h 0 is given, nominating stdin as the file descriptor on which to read the password. Note that this password will be read only once and is intended for use by a script rather than for interactive use. If you wish to have new password confir- mation along the lines of passwd(1), this must be imple- mented as part of an interactive script that calls pw. If a value of `-' is given as the argument fd, then the password will be set to `*', rendering the account inacces- sible via password-based login. Read more in man 8 pw. I'm also sure that there are examples out there as well if you search on Google, etc. -Garrett