Posted: . At: 9:47 PM. This was 11 years ago. Post ID: 6161
Page permalink. WordPress uses cookies, or tiny pieces of information stored on your computer, to verify who you are. There are cookies for logged in users and for commenters.
These cookies expire two weeks after they are set.

How to create users on a Linux system in batches with the newusers command.

The newusers command available on Linux allows you to create users in batches. This could also be automated with a shell script and quickly done on a new system that is to be shared by many users.

anders:754787547:1500:1500:Anders Smith:/home/anders:/bin/bash
johnc:4767577474:1501:1501:John Citizen:/home/johnc:/bin/bash
akmed:4565y4gr454h:1502:1502:Akmed Islam:/home/akmed:/bin/bash

Above is the list of new users. This is written out in the same format as the /etc/passwd file and contains all of the information about the new users.

Put the above information into a file named users.txt and then type this command as root to add them to your system.

newusers users.txt

This will create all of the users that you have defined in the users.txt file. Just make sure there is no newline at the end of the file or you will get an error.

After that; type cat /etc/shadow as root and you will see your newly created users at the bottom.

anders:$6$msIf7/kKQLxFk$A0kZY1Z9c5dVE4RhaesLISQ.suvc7qy6EYkB/eE9PzL9aeHpkkJ65dExU35skdMq9asv2LSbZb/uv7bjqGM7L/:15940:0:99999:7:::
johnc:$6$hjgdh/ETW.H/0Irb$5OrbXg1RikWe1AauUZI04YLyW42wzKnHvgo3w46QHVFR8MqWSXFcUmbBAPAx4UtnzhwMaheDGEeoabJekOhvx1:15940:0:99999:7:::
akmed:$6$2CokG/Ydded/.N$mSK0TPQlaV62kN2BQUQREXGbRZme6FUXCTeuQBxIH3qC1s5pDZjRwHvKusk2gw7Wuymby0RDb58fDeozduNPM/:15940:0:99999:7:::

And here they are in the /etc/passwd file.

anders:x:1500:1500:Anders Smith:/home/anders:/bin/bash
johnc:x:1501:1501:John Citizen:/home/johnc:/bin/bash
akmed:x:1502:1502:Akmed Islam:/home/akmed:/bin/bash

That is how easy it is to create a bunch of new users on your Linux system. Try it yourself and see.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.