Jez Hancock wrote:
I'm attempting to use pw adduser to add a new user to the system and
would like confirmation that the following is the correct way to set
the user's password at the same time:

echo "password" | \
pw adduser -q -h - -u user -g group -s shell -d /home/user -c comment

Can anyone also tell me the security implications of doing this, given
that the command is executed from a within a script (actually php but
this is more-or-less irrelevant)?

Here is what I use:

  echo 'password' | \
  pw useradd -q -h 0 -n user -g group -s shell -d /home/user \
    -c 'comment' -m

Note that feeding the password to 'pw' via the command line (with 'echo') is a security problem if you have untrusted users on that machine, since they can see the password in the process list (with 'ps').

A better approach for automating account creation is to first store the password (generated or given) in a file (with secure permissions, of course) and then feed 'pw' from that file:

  pw useradd -q -h 0 -n user -g group -s shell -d /home/user \
    -c 'comment' -m < /path/to/file
  rm -f /path/to/file

Hope that helps.

Uwe Doering         |  EscapeBox - Managed On-Demand UNIX Servers

[EMAIL PROTECTED] mailing list
To unsubscribe, send any mail to "[EMAIL PROTECTED]"

Reply via email to