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

    Scripting password setup help please


    Hi,

    I'm writing some scripts to automate some tasks and I'm creating a new user and want to set the password in the script automatically. Please can anyone help with this?

    Im using the following command to create the user.

    Code:
    useradd -s /bin/bash -g user1 -m -k /dev/null users
    and then i have 'passwd user1' next but it waits for the users input to create the password. How can I automate this to just put a pre-defined password in itself without the users input?

    Thanks

  2. #2
    Trusted Penguin Irithori's Avatar
    Join Date
    May 2009
    Location
    Munich
    Posts
    4,031
    I would advise not to reinvent the wheel and instead use one of the established automation tools like ansible, chef puppet or salt.
    They offer methods to manage users.
    You must always face the curtain with a bow.

  3. #3
    Linux Newbie sarlacii's Avatar
    Join Date
    May 2005
    Location
    South Africa
    Posts
    223
    -->
    Quote Originally Posted by aaronmarsh632 View Post
    then i have 'passwd user1' next but it waits for the users input to create the password
    The passwd tool is specifically written to ask for user input, although some versions come with a --stdin command line switch that allows pipe manipulation. Irithori is correct in that you should look at using another tool, more suited to the purpose. However, you can brute force the issue via the "chpasswd" utility instead (see threads like this). On openSuse the utility is part of the shadow package:
    Code:
    Program 'chpasswd' is present in package 'shadow', which is installed on your system.
    
    Absolute path to 'chpasswd' is '/usr/sbin/chpasswd', so running it may require superuser privileges (eg. root).
    Go well.
    Last edited by sarlacii; 02-02-2018 at 10:45 AM. Reason: changed tags

$spacer_open
$spacer_close

Posting Permissions

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