How to create user and password in one script for 100+ users

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
-4
down vote

favorite












I have written a script for adding and setting password for 100+ users. Eg: for setting password of the user I want to set in "user+123" format for all the users I.e user will change according to the username in password.
How can I write a script for this.



#!/bin/bash
for i in `more users.txt`
do
useradd $i;
echo "User $i added successfully"
passwd $("$i"123)
echo "Password added successfully for user"
done






share|improve this question


















  • 1




    Please do not use photos were text will do. It is not that difficult typing in that script.
    – Rui F Ribeiro
    Jan 23 at 12:37






  • 2




    I would look at changing the passwords for users in batch mode using chpasswd.
    – Raman Sailopal
    Jan 23 at 13:12














up vote
-4
down vote

favorite












I have written a script for adding and setting password for 100+ users. Eg: for setting password of the user I want to set in "user+123" format for all the users I.e user will change according to the username in password.
How can I write a script for this.



#!/bin/bash
for i in `more users.txt`
do
useradd $i;
echo "User $i added successfully"
passwd $("$i"123)
echo "Password added successfully for user"
done






share|improve this question


















  • 1




    Please do not use photos were text will do. It is not that difficult typing in that script.
    – Rui F Ribeiro
    Jan 23 at 12:37






  • 2




    I would look at changing the passwords for users in batch mode using chpasswd.
    – Raman Sailopal
    Jan 23 at 13:12












up vote
-4
down vote

favorite









up vote
-4
down vote

favorite











I have written a script for adding and setting password for 100+ users. Eg: for setting password of the user I want to set in "user+123" format for all the users I.e user will change according to the username in password.
How can I write a script for this.



#!/bin/bash
for i in `more users.txt`
do
useradd $i;
echo "User $i added successfully"
passwd $("$i"123)
echo "Password added successfully for user"
done






share|improve this question














I have written a script for adding and setting password for 100+ users. Eg: for setting password of the user I want to set in "user+123" format for all the users I.e user will change according to the username in password.
How can I write a script for this.



#!/bin/bash
for i in `more users.txt`
do
useradd $i;
echo "User $i added successfully"
passwd $("$i"123)
echo "Password added successfully for user"
done








share|improve this question













share|improve this question




share|improve this question








edited Jan 23 at 12:51









Hunter.S.Thompson

4,50631334




4,50631334










asked Jan 23 at 12:33









Monika

11




11







  • 1




    Please do not use photos were text will do. It is not that difficult typing in that script.
    – Rui F Ribeiro
    Jan 23 at 12:37






  • 2




    I would look at changing the passwords for users in batch mode using chpasswd.
    – Raman Sailopal
    Jan 23 at 13:12












  • 1




    Please do not use photos were text will do. It is not that difficult typing in that script.
    – Rui F Ribeiro
    Jan 23 at 12:37






  • 2




    I would look at changing the passwords for users in batch mode using chpasswd.
    – Raman Sailopal
    Jan 23 at 13:12







1




1




Please do not use photos were text will do. It is not that difficult typing in that script.
– Rui F Ribeiro
Jan 23 at 12:37




Please do not use photos were text will do. It is not that difficult typing in that script.
– Rui F Ribeiro
Jan 23 at 12:37




2




2




I would look at changing the passwords for users in batch mode using chpasswd.
– Raman Sailopal
Jan 23 at 13:12




I would look at changing the passwords for users in batch mode using chpasswd.
– Raman Sailopal
Jan 23 at 13:12










3 Answers
3






active

oldest

votes

















up vote
2
down vote













#!/bin/bash
for i in $( cat users.txt ); do
useradd $i
echo "user $i added successfully!"
echo $i:$i"123" | chpasswd
echo "Password for user $i changed successfully"
done


This little script should be what you are looking for. It adds the user first, then proceeds to change the password. Avoid using backticks, as they are deprecated, $() is a good alternative.






share|improve this answer






















  • Please give a reason for the downvote, maybe I can learn something, something I did wrong?
    – Hunter.S.Thompson
    Jan 23 at 16:59










  • Where do you see that back ticks are deprecated? It says nothing about that in the official manual. gnu.org/software/bash/manual/bashref.html#Command-Substitution
    – Nathan Adams
    Aug 3 at 4:09










  • @NathanAdams, unix.stackexchange.com/a/126928/237568
    – Hunter.S.Thompson
    Aug 3 at 13:35










  • en.wikipedia.org/wiki/Deprecation
    – Hunter.S.Thompson
    Aug 3 at 13:40










  • @Hunter.S.Thompson Works like a charm , thanks alot
    – somethingSomething
    Aug 22 at 5:56

















up vote
1
down vote













The other answers provide technical answers for how to do this. But please don't do this.



As soon as a threat actor sees the pattern, they could log in as any other user. (And even if you force a password change on first login, someone could lock out all of the other users.)



Instead, send each user a random password, or a token via email to be used to set a new password.






share|improve this answer



























    up vote
    0
    down vote













    In below script i am creating 5 users like user1,user2,user3,user4,user5 and setting the pasword as "username+123" for each user Tested and it worked successfully.



    You can change number of users as per requirment



    for i in user1..5; do useradd $i; passwd -d $i; echo $i"123" | passwd $i --stdin; done


    If you have a text file in which you have specific usernames, you can use



    for i in $(cat users.txt); do useradd $i; passwd -d $i; echo $i"123" | passwd $i --stdin; done





    share|improve this answer






















    • OP wants the users to have unique names, and the password should be $user123, your answer does not accommodate that.
      – Hunter.S.Thompson
      Jan 23 at 16:03










    • @Hunter.S.Thompson Edited the answer and changed as per the requirement and tested too . its working fine
      – Praveen Kumar BS
      Jan 23 at 16:49










    • I edited your answer to properly show what the OP needs to do when the usernames are in a textfile.
      – Hunter.S.Thompson
      Jan 23 at 16:55










    Your Answer







    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "106"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    convertImagesToLinks: false,
    noModals: false,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );








     

    draft saved


    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f419063%2fhow-to-create-user-and-password-in-one-script-for-100-users%23new-answer', 'question_page');

    );

    Post as a guest






























    3 Answers
    3






    active

    oldest

    votes








    3 Answers
    3






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    2
    down vote













    #!/bin/bash
    for i in $( cat users.txt ); do
    useradd $i
    echo "user $i added successfully!"
    echo $i:$i"123" | chpasswd
    echo "Password for user $i changed successfully"
    done


    This little script should be what you are looking for. It adds the user first, then proceeds to change the password. Avoid using backticks, as they are deprecated, $() is a good alternative.






    share|improve this answer






















    • Please give a reason for the downvote, maybe I can learn something, something I did wrong?
      – Hunter.S.Thompson
      Jan 23 at 16:59










    • Where do you see that back ticks are deprecated? It says nothing about that in the official manual. gnu.org/software/bash/manual/bashref.html#Command-Substitution
      – Nathan Adams
      Aug 3 at 4:09










    • @NathanAdams, unix.stackexchange.com/a/126928/237568
      – Hunter.S.Thompson
      Aug 3 at 13:35










    • en.wikipedia.org/wiki/Deprecation
      – Hunter.S.Thompson
      Aug 3 at 13:40










    • @Hunter.S.Thompson Works like a charm , thanks alot
      – somethingSomething
      Aug 22 at 5:56














    up vote
    2
    down vote













    #!/bin/bash
    for i in $( cat users.txt ); do
    useradd $i
    echo "user $i added successfully!"
    echo $i:$i"123" | chpasswd
    echo "Password for user $i changed successfully"
    done


    This little script should be what you are looking for. It adds the user first, then proceeds to change the password. Avoid using backticks, as they are deprecated, $() is a good alternative.






    share|improve this answer






















    • Please give a reason for the downvote, maybe I can learn something, something I did wrong?
      – Hunter.S.Thompson
      Jan 23 at 16:59










    • Where do you see that back ticks are deprecated? It says nothing about that in the official manual. gnu.org/software/bash/manual/bashref.html#Command-Substitution
      – Nathan Adams
      Aug 3 at 4:09










    • @NathanAdams, unix.stackexchange.com/a/126928/237568
      – Hunter.S.Thompson
      Aug 3 at 13:35










    • en.wikipedia.org/wiki/Deprecation
      – Hunter.S.Thompson
      Aug 3 at 13:40










    • @Hunter.S.Thompson Works like a charm , thanks alot
      – somethingSomething
      Aug 22 at 5:56












    up vote
    2
    down vote










    up vote
    2
    down vote









    #!/bin/bash
    for i in $( cat users.txt ); do
    useradd $i
    echo "user $i added successfully!"
    echo $i:$i"123" | chpasswd
    echo "Password for user $i changed successfully"
    done


    This little script should be what you are looking for. It adds the user first, then proceeds to change the password. Avoid using backticks, as they are deprecated, $() is a good alternative.






    share|improve this answer














    #!/bin/bash
    for i in $( cat users.txt ); do
    useradd $i
    echo "user $i added successfully!"
    echo $i:$i"123" | chpasswd
    echo "Password for user $i changed successfully"
    done


    This little script should be what you are looking for. It adds the user first, then proceeds to change the password. Avoid using backticks, as they are deprecated, $() is a good alternative.







    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Jan 23 at 16:53









    Alexander

    5,57812043




    5,57812043










    answered Jan 23 at 12:55









    Hunter.S.Thompson

    4,50631334




    4,50631334











    • Please give a reason for the downvote, maybe I can learn something, something I did wrong?
      – Hunter.S.Thompson
      Jan 23 at 16:59










    • Where do you see that back ticks are deprecated? It says nothing about that in the official manual. gnu.org/software/bash/manual/bashref.html#Command-Substitution
      – Nathan Adams
      Aug 3 at 4:09










    • @NathanAdams, unix.stackexchange.com/a/126928/237568
      – Hunter.S.Thompson
      Aug 3 at 13:35










    • en.wikipedia.org/wiki/Deprecation
      – Hunter.S.Thompson
      Aug 3 at 13:40










    • @Hunter.S.Thompson Works like a charm , thanks alot
      – somethingSomething
      Aug 22 at 5:56
















    • Please give a reason for the downvote, maybe I can learn something, something I did wrong?
      – Hunter.S.Thompson
      Jan 23 at 16:59










    • Where do you see that back ticks are deprecated? It says nothing about that in the official manual. gnu.org/software/bash/manual/bashref.html#Command-Substitution
      – Nathan Adams
      Aug 3 at 4:09










    • @NathanAdams, unix.stackexchange.com/a/126928/237568
      – Hunter.S.Thompson
      Aug 3 at 13:35










    • en.wikipedia.org/wiki/Deprecation
      – Hunter.S.Thompson
      Aug 3 at 13:40










    • @Hunter.S.Thompson Works like a charm , thanks alot
      – somethingSomething
      Aug 22 at 5:56















    Please give a reason for the downvote, maybe I can learn something, something I did wrong?
    – Hunter.S.Thompson
    Jan 23 at 16:59




    Please give a reason for the downvote, maybe I can learn something, something I did wrong?
    – Hunter.S.Thompson
    Jan 23 at 16:59












    Where do you see that back ticks are deprecated? It says nothing about that in the official manual. gnu.org/software/bash/manual/bashref.html#Command-Substitution
    – Nathan Adams
    Aug 3 at 4:09




    Where do you see that back ticks are deprecated? It says nothing about that in the official manual. gnu.org/software/bash/manual/bashref.html#Command-Substitution
    – Nathan Adams
    Aug 3 at 4:09












    @NathanAdams, unix.stackexchange.com/a/126928/237568
    – Hunter.S.Thompson
    Aug 3 at 13:35




    @NathanAdams, unix.stackexchange.com/a/126928/237568
    – Hunter.S.Thompson
    Aug 3 at 13:35












    en.wikipedia.org/wiki/Deprecation
    – Hunter.S.Thompson
    Aug 3 at 13:40




    en.wikipedia.org/wiki/Deprecation
    – Hunter.S.Thompson
    Aug 3 at 13:40












    @Hunter.S.Thompson Works like a charm , thanks alot
    – somethingSomething
    Aug 22 at 5:56




    @Hunter.S.Thompson Works like a charm , thanks alot
    – somethingSomething
    Aug 22 at 5:56












    up vote
    1
    down vote













    The other answers provide technical answers for how to do this. But please don't do this.



    As soon as a threat actor sees the pattern, they could log in as any other user. (And even if you force a password change on first login, someone could lock out all of the other users.)



    Instead, send each user a random password, or a token via email to be used to set a new password.






    share|improve this answer
























      up vote
      1
      down vote













      The other answers provide technical answers for how to do this. But please don't do this.



      As soon as a threat actor sees the pattern, they could log in as any other user. (And even if you force a password change on first login, someone could lock out all of the other users.)



      Instead, send each user a random password, or a token via email to be used to set a new password.






      share|improve this answer






















        up vote
        1
        down vote










        up vote
        1
        down vote









        The other answers provide technical answers for how to do this. But please don't do this.



        As soon as a threat actor sees the pattern, they could log in as any other user. (And even if you force a password change on first login, someone could lock out all of the other users.)



        Instead, send each user a random password, or a token via email to be used to set a new password.






        share|improve this answer












        The other answers provide technical answers for how to do this. But please don't do this.



        As soon as a threat actor sees the pattern, they could log in as any other user. (And even if you force a password change on first login, someone could lock out all of the other users.)



        Instead, send each user a random password, or a token via email to be used to set a new password.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Jan 28 at 21:37









        Royce Williams

        635618




        635618




















            up vote
            0
            down vote













            In below script i am creating 5 users like user1,user2,user3,user4,user5 and setting the pasword as "username+123" for each user Tested and it worked successfully.



            You can change number of users as per requirment



            for i in user1..5; do useradd $i; passwd -d $i; echo $i"123" | passwd $i --stdin; done


            If you have a text file in which you have specific usernames, you can use



            for i in $(cat users.txt); do useradd $i; passwd -d $i; echo $i"123" | passwd $i --stdin; done





            share|improve this answer






















            • OP wants the users to have unique names, and the password should be $user123, your answer does not accommodate that.
              – Hunter.S.Thompson
              Jan 23 at 16:03










            • @Hunter.S.Thompson Edited the answer and changed as per the requirement and tested too . its working fine
              – Praveen Kumar BS
              Jan 23 at 16:49










            • I edited your answer to properly show what the OP needs to do when the usernames are in a textfile.
              – Hunter.S.Thompson
              Jan 23 at 16:55














            up vote
            0
            down vote













            In below script i am creating 5 users like user1,user2,user3,user4,user5 and setting the pasword as "username+123" for each user Tested and it worked successfully.



            You can change number of users as per requirment



            for i in user1..5; do useradd $i; passwd -d $i; echo $i"123" | passwd $i --stdin; done


            If you have a text file in which you have specific usernames, you can use



            for i in $(cat users.txt); do useradd $i; passwd -d $i; echo $i"123" | passwd $i --stdin; done





            share|improve this answer






















            • OP wants the users to have unique names, and the password should be $user123, your answer does not accommodate that.
              – Hunter.S.Thompson
              Jan 23 at 16:03










            • @Hunter.S.Thompson Edited the answer and changed as per the requirement and tested too . its working fine
              – Praveen Kumar BS
              Jan 23 at 16:49










            • I edited your answer to properly show what the OP needs to do when the usernames are in a textfile.
              – Hunter.S.Thompson
              Jan 23 at 16:55












            up vote
            0
            down vote










            up vote
            0
            down vote









            In below script i am creating 5 users like user1,user2,user3,user4,user5 and setting the pasword as "username+123" for each user Tested and it worked successfully.



            You can change number of users as per requirment



            for i in user1..5; do useradd $i; passwd -d $i; echo $i"123" | passwd $i --stdin; done


            If you have a text file in which you have specific usernames, you can use



            for i in $(cat users.txt); do useradd $i; passwd -d $i; echo $i"123" | passwd $i --stdin; done





            share|improve this answer














            In below script i am creating 5 users like user1,user2,user3,user4,user5 and setting the pasword as "username+123" for each user Tested and it worked successfully.



            You can change number of users as per requirment



            for i in user1..5; do useradd $i; passwd -d $i; echo $i"123" | passwd $i --stdin; done


            If you have a text file in which you have specific usernames, you can use



            for i in $(cat users.txt); do useradd $i; passwd -d $i; echo $i"123" | passwd $i --stdin; done






            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Jan 23 at 16:54









            Hunter.S.Thompson

            4,50631334




            4,50631334










            answered Jan 23 at 14:24









            Praveen Kumar BS

            1,010128




            1,010128











            • OP wants the users to have unique names, and the password should be $user123, your answer does not accommodate that.
              – Hunter.S.Thompson
              Jan 23 at 16:03










            • @Hunter.S.Thompson Edited the answer and changed as per the requirement and tested too . its working fine
              – Praveen Kumar BS
              Jan 23 at 16:49










            • I edited your answer to properly show what the OP needs to do when the usernames are in a textfile.
              – Hunter.S.Thompson
              Jan 23 at 16:55
















            • OP wants the users to have unique names, and the password should be $user123, your answer does not accommodate that.
              – Hunter.S.Thompson
              Jan 23 at 16:03










            • @Hunter.S.Thompson Edited the answer and changed as per the requirement and tested too . its working fine
              – Praveen Kumar BS
              Jan 23 at 16:49










            • I edited your answer to properly show what the OP needs to do when the usernames are in a textfile.
              – Hunter.S.Thompson
              Jan 23 at 16:55















            OP wants the users to have unique names, and the password should be $user123, your answer does not accommodate that.
            – Hunter.S.Thompson
            Jan 23 at 16:03




            OP wants the users to have unique names, and the password should be $user123, your answer does not accommodate that.
            – Hunter.S.Thompson
            Jan 23 at 16:03












            @Hunter.S.Thompson Edited the answer and changed as per the requirement and tested too . its working fine
            – Praveen Kumar BS
            Jan 23 at 16:49




            @Hunter.S.Thompson Edited the answer and changed as per the requirement and tested too . its working fine
            – Praveen Kumar BS
            Jan 23 at 16:49












            I edited your answer to properly show what the OP needs to do when the usernames are in a textfile.
            – Hunter.S.Thompson
            Jan 23 at 16:55




            I edited your answer to properly show what the OP needs to do when the usernames are in a textfile.
            – Hunter.S.Thompson
            Jan 23 at 16:55












             

            draft saved


            draft discarded


























             


            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f419063%2fhow-to-create-user-and-password-in-one-script-for-100-users%23new-answer', 'question_page');

            );

            Post as a guest













































































            Popular posts from this blog

            How to check contact read email or not when send email to Individual?

            Displaying single band from multi-band raster using QGIS

            How many registers does an x86_64 CPU actually have?