Date: Mon, 16 Jan 2006 22:17:37 -0800 From: Garrett Cooper <youshi10@u.washington.edu> To: freebsd-questions@freebsd.org Subject: Re: how do I (non-interactively) change a users password in a script ? Message-ID: <43CC8C01.2020703@u.washington.edu> In-Reply-To: <Pine.LNX.4.21.0601170101390.8684-100000@shell.dhp.com> References: <Pine.LNX.4.21.0601170101390.8684-100000@shell.dhp.com>
next in thread | previous in thread | raw e-mail | index | archive | help
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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?43CC8C01.2020703>