Create multiple username and UID in Linux using shell script

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











up vote
2
down vote

favorite












In my environment I constantly have to attach an NFS server running on Linux. The Linux client system has user names created in it and they are in a sequential order. But in order to set the sharing permission for each user individually, I have to create them using useradd -u 2001 -g 1000 -d /home/app/mnt/1 user1 in my NFS server. If my client system has 1000 users I have to individually crate them on my NFS server too.



I want to create multiple user names and assign an UID (not random) using shell script in my Linux NFS server. I also want to assign them a home directory automatically. For example I want to create users like



| Username| UID |Home Directory|
| user1 |20001|/home/users/1 |
| user2 |20002|/home/users/2 |
| user3 |20003|/home/users/3 |
| . | . | . |
| . | . | . |
| . | . | . |
| userX |2000X|/home/users/X |


User name always starts with "user", it remains the same. X could be 100 to 1000.



These users are necessary but short lived hence I don't want to go for a central user management platform. Is it possible that a shell script can create users in bulk?



I went through this article. This starts with exactly what I want, but later goes into things which makes no sense to me.










share|improve this question



















  • 1




    "necessary but short lived" To me, that sounds like an excellent reason to use a user database other than files—a lot of them are far easier to interact with programmatically (e.g., your favorite programming/scripting language has LDAP and SQL interfaces), and you don't have to worry about syncing between systems.
    – derobert
    Jun 1 '16 at 19:54














up vote
2
down vote

favorite












In my environment I constantly have to attach an NFS server running on Linux. The Linux client system has user names created in it and they are in a sequential order. But in order to set the sharing permission for each user individually, I have to create them using useradd -u 2001 -g 1000 -d /home/app/mnt/1 user1 in my NFS server. If my client system has 1000 users I have to individually crate them on my NFS server too.



I want to create multiple user names and assign an UID (not random) using shell script in my Linux NFS server. I also want to assign them a home directory automatically. For example I want to create users like



| Username| UID |Home Directory|
| user1 |20001|/home/users/1 |
| user2 |20002|/home/users/2 |
| user3 |20003|/home/users/3 |
| . | . | . |
| . | . | . |
| . | . | . |
| userX |2000X|/home/users/X |


User name always starts with "user", it remains the same. X could be 100 to 1000.



These users are necessary but short lived hence I don't want to go for a central user management platform. Is it possible that a shell script can create users in bulk?



I went through this article. This starts with exactly what I want, but later goes into things which makes no sense to me.










share|improve this question



















  • 1




    "necessary but short lived" To me, that sounds like an excellent reason to use a user database other than files—a lot of them are far easier to interact with programmatically (e.g., your favorite programming/scripting language has LDAP and SQL interfaces), and you don't have to worry about syncing between systems.
    – derobert
    Jun 1 '16 at 19:54












up vote
2
down vote

favorite









up vote
2
down vote

favorite











In my environment I constantly have to attach an NFS server running on Linux. The Linux client system has user names created in it and they are in a sequential order. But in order to set the sharing permission for each user individually, I have to create them using useradd -u 2001 -g 1000 -d /home/app/mnt/1 user1 in my NFS server. If my client system has 1000 users I have to individually crate them on my NFS server too.



I want to create multiple user names and assign an UID (not random) using shell script in my Linux NFS server. I also want to assign them a home directory automatically. For example I want to create users like



| Username| UID |Home Directory|
| user1 |20001|/home/users/1 |
| user2 |20002|/home/users/2 |
| user3 |20003|/home/users/3 |
| . | . | . |
| . | . | . |
| . | . | . |
| userX |2000X|/home/users/X |


User name always starts with "user", it remains the same. X could be 100 to 1000.



These users are necessary but short lived hence I don't want to go for a central user management platform. Is it possible that a shell script can create users in bulk?



I went through this article. This starts with exactly what I want, but later goes into things which makes no sense to me.










share|improve this question















In my environment I constantly have to attach an NFS server running on Linux. The Linux client system has user names created in it and they are in a sequential order. But in order to set the sharing permission for each user individually, I have to create them using useradd -u 2001 -g 1000 -d /home/app/mnt/1 user1 in my NFS server. If my client system has 1000 users I have to individually crate them on my NFS server too.



I want to create multiple user names and assign an UID (not random) using shell script in my Linux NFS server. I also want to assign them a home directory automatically. For example I want to create users like



| Username| UID |Home Directory|
| user1 |20001|/home/users/1 |
| user2 |20002|/home/users/2 |
| user3 |20003|/home/users/3 |
| . | . | . |
| . | . | . |
| . | . | . |
| userX |2000X|/home/users/X |


User name always starts with "user", it remains the same. X could be 100 to 1000.



These users are necessary but short lived hence I don't want to go for a central user management platform. Is it possible that a shell script can create users in bulk?



I went through this article. This starts with exactly what I want, but later goes into things which makes no sense to me.







linux shell-script useradd






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Dec 7 at 23:46









Rui F Ribeiro

38.7k1479128




38.7k1479128










asked Jun 1 '16 at 19:35









Arvind

134




134







  • 1




    "necessary but short lived" To me, that sounds like an excellent reason to use a user database other than files—a lot of them are far easier to interact with programmatically (e.g., your favorite programming/scripting language has LDAP and SQL interfaces), and you don't have to worry about syncing between systems.
    – derobert
    Jun 1 '16 at 19:54












  • 1




    "necessary but short lived" To me, that sounds like an excellent reason to use a user database other than files—a lot of them are far easier to interact with programmatically (e.g., your favorite programming/scripting language has LDAP and SQL interfaces), and you don't have to worry about syncing between systems.
    – derobert
    Jun 1 '16 at 19:54







1




1




"necessary but short lived" To me, that sounds like an excellent reason to use a user database other than files—a lot of them are far easier to interact with programmatically (e.g., your favorite programming/scripting language has LDAP and SQL interfaces), and you don't have to worry about syncing between systems.
– derobert
Jun 1 '16 at 19:54




"necessary but short lived" To me, that sounds like an excellent reason to use a user database other than files—a lot of them are far easier to interact with programmatically (e.g., your favorite programming/scripting language has LDAP and SQL interfaces), and you don't have to worry about syncing between systems.
– derobert
Jun 1 '16 at 19:54










1 Answer
1






active

oldest

votes

















up vote
2
down vote



accepted










As suggested, this is fairly easy to accomplish. On the terminal you could use a for loop like this:



for i in 20001..20100; do useradd -u $i -g 1000 -d /home/app/mnt/$i "user$i"; done


The loop is incremented up to 20100 and then it quits.






share|improve this answer




















    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: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    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%2f286998%2fcreate-multiple-username-and-uid-in-linux-using-shell-script%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    2
    down vote



    accepted










    As suggested, this is fairly easy to accomplish. On the terminal you could use a for loop like this:



    for i in 20001..20100; do useradd -u $i -g 1000 -d /home/app/mnt/$i "user$i"; done


    The loop is incremented up to 20100 and then it quits.






    share|improve this answer
























      up vote
      2
      down vote



      accepted










      As suggested, this is fairly easy to accomplish. On the terminal you could use a for loop like this:



      for i in 20001..20100; do useradd -u $i -g 1000 -d /home/app/mnt/$i "user$i"; done


      The loop is incremented up to 20100 and then it quits.






      share|improve this answer






















        up vote
        2
        down vote



        accepted







        up vote
        2
        down vote



        accepted






        As suggested, this is fairly easy to accomplish. On the terminal you could use a for loop like this:



        for i in 20001..20100; do useradd -u $i -g 1000 -d /home/app/mnt/$i "user$i"; done


        The loop is incremented up to 20100 and then it quits.






        share|improve this answer












        As suggested, this is fairly easy to accomplish. On the terminal you could use a for loop like this:



        for i in 20001..20100; do useradd -u $i -g 1000 -d /home/app/mnt/$i "user$i"; done


        The loop is incremented up to 20100 and then it quits.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Jun 1 '16 at 19:55









        Valentin Bajrami

        5,80411627




        5,80411627



























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Unix & Linux Stack Exchange!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f286998%2fcreate-multiple-username-and-uid-in-linux-using-shell-script%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown






            Popular posts from this blog

            Peggy Mitchell

            The Forum (Inglewood, California)

            Palaiologos