Find the answer to your Linux question:
Results 1 to 6 of 6
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    Creating user + password directly

    Hey guys,
    I have a couple of questions for CENTOS 5.5FINAL x86_64 os..
    I need a command that will create a user + password directly(will be used in php..)
    like useradd wtest -p 123456 (should work in the useradd help, but for some reason doesnt, maybe need the encrypted part of 123456?)
    and another that will change a user directly like password wtest 123456
    and not via passwd, because i dont think it can be used in php...


  2. #2
    Linux User cheesecake42's Avatar
    Join Date
    Jan 2007
    Orlando, FL
    If your goal is to include the new password inside the passwd command this will not be possible. They do this for security reasons. Using the passwd command requires user input after the command has been typed. You can run the useradd and passwd command in a single command though such as:
    useradd newuser && passwd newuser
    but still using the above command will still require user input for the actual password change.

  3. #3
    assign the user a null password
    # usermod -p "" newuser
    make the password expire immediately
    # chage -d 0 newuser

  4. $spacer_open
  5. #4
    Linux Newbie nplusplus's Avatar
    Join Date
    Apr 2010
    Charlotte, NC, USA
    You could update the system user database directly (/etc/passwd) or use the chpasswd command (available on CentOS 5.5, see "man chpasswd").

    If updating the db directly, you would probably also want to mimic the behavior of useradd in other ways, like the copying of /etc/skel for home directories. You would also need to encrypt the password beforehand using crypt, openssl, or grub-md5-crypt.

    If you use chpasswd, you have the option to supply passwords in plaintext or encrypted depending on the options you pass.

  6. #5
    useradd -p$(perl -e 'print crypt($ARGV[0], "saltrandom")' "password") user

    I've used this-^

    In theory this should work but havent tried -\
    usermod-p$(perl -e 'print crypt($ARGV[0], "saltxyyzzy")' "password") me

    Edit to mention - 1 reason clear text passwords arent used directly in a command line are in theory it could be captured in a process listing.

  7. #6
    Just Joined! NightShade03's Avatar
    Join Date
    Apr 2010
    New York
    useradd -c "Local User" -m -s /bin/bash user01 && echo "user01:my_pass" | chpasswd

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts