How to create bulk user from csv in openldap server

We all want to know how we can create bulk users if we have excell or csv file in our hand only?
I am telling you the solution.
First let me make you very clear openldap cannot accept excel or csv format directly. It is possible to   generate a ldif file from  csv and then we can use ldapadd command to add all users.
So here
i have created a shell script to convert csv to ldif.

1. Create a file named create.awk   and paste bellow script lines and save it.

BEGIN {
start_uid = 501;
start_gid = 502;
i=0;
}
{
print "dn: uid="$1", ou=People,dc=mydomain,dc=com"
print "givenName: ",$2
print "sn: ",$3
print "loginShell: /bin/bash" 
print "uidNumber : "(start_uid+i); 
print "gidNumber : "(start_gid+i); 
print "shadowMax: 99999" 
print "mail: "$1"@mydomain.com"
print "objectClass: person" 
print "objectClass: top"
print "objectClass: organizationalPerson"
print "objectClass: inetOrgPerson"
print "objectClass: posixAccount" 
print "objectClass: shadowAccount"
print "uid: "$1
print "shadowLastChange: 12994"
print "cn: "$2$3 
print "homeDirectory: /home/"$1
print "shadowWarning: 7" 
print "userPassword: "$2$1
print "\n";  
 
i++; 
}


2.Make this file executable
 # chmod +x create.awk

now you must have a csv file having three field defined
First column  => uid
second column => first name
third column   => last name

3.  Run bellow command to create ldif file

# awk  -F"," -f create.awk users.csv >users.ldif
4. Now run bellow ldapadd command on your openldap server.

# ldapadd -x -D "cn=manager,dc=mydomain,dc=com" -w password -f  users.ldif

note : change dc=mydomain,dc=com from your base dn and password from your original password.














Comments

  1. your script worked , good!

    but how can import with chinese character

    import with chinese character have error

    ReplyDelete
  2. Kindly provide bulladduser.csv format

    ReplyDelete
    Replies
    1. Please check now you must have a csv file having three field defined
      First column => uid
      second column => first name
      third column => last name

      Delete
  3. Great article by the great author, it is very massive and informative but still preaches the way to sounds like that it has some beautiful thoughts described so I really appreciate this article. Best bulk email server service provider.

    ReplyDelete

Post a Comment

Popular posts from this blog

Running web ssh client on port 443 /80 with nginx as reverse proxy

Running cockpit behind nginx reverse proxy with nginx ssl and cockpit non ssl

Setup VOD streaming server with nginx using RTMP on Ubuntu 18.04