Ubuntu – Import users from CSV file

csvuser-managementusers

Is it possible to import users by using CSV file? or something like a LDAP connection to import all users?

Best Answer

There's an app for that! The newusers tool which is part of the passwd package is designed to batch create users:

DESCRIPTION
   The newusers command reads a file (or the standard input by default)
   and uses this information to update a set of existing users or to
   create new users. Each line is in the same format as the standard
   password file (see passwd(5)) with the exceptions explained below:

You will need to create a file with this format:

username:passwd:UID:GID:full name,room number,work phone,home phone,other:directory:shell

Many of these can be ignored and the default values will be used. You only need to specify the username and password. For example:

tom:password1:::::
danny:password2:::::

If I save that as users.txt and run this command:

sudo newusers < users.txt 

The users are created:

$ grep -E 'tom|danny' /etc/passwd
tom:x:1005:1006:::
danny:x:1006:1007:::
Related Question