How to migrate users from passwd to openldap

Following tutorial will describe how to migrate system passwd users to openldap.

Lets Assume we have five users from user1 to user5 in the system ( eg. user1, user2, user3, user4, and  user5 ) and five groups ( eg. user1, user2, user3, user4, and user5 ).

Step-1  Install migration script package. 

[ root @server~ ]#   yum    install   migrationtools

 

Step-2  Now extract users, user's password and group into new file.

[ root @server~ ]#    getent   passwd    |  tail   -n5   >   /tmp/passwd

[ root @server~ ]#    getent   shadow    |  tail   -n5   >   /tmp/shadow

[ root @server~ ]#    getent   group       |  tail   -n5   >   /tmp/group

 

Step-3  Edit Migrationtool scripts according to your ldap server configuration.

[ root @server~ ]#   cd   /usr/share/migrationtools/

[ root @server~ ]#   vim   migrate_common.ph 
Line No-61     $NAMINGCONTEXT{'group'}             = "ou=Groups"; 
Line No-71     $DEFAULT_MAIL_DOMAIN = "leolinux.in";
Line No-74     $DEFAULT_BASE = "dc=leolinux,dc=in";
Line No-90     $EXTENDED_SCHEMA = 1;
 
[ root @server~ ]#   vim   migrate_passwd.pl
Line No-188   open(SHADOW, "/tmp/shadow") || return;

 

Step-4  Now create ldif file.

[ root @server~ ]#    cd   /usr/share/migrationtools/

[ root @server~ ]#   ./migrate_base.pl      /tmp/base.ldif 

[ root @server~ ]#   ./migrate_passwd.pl   /tmp/passwd    >   /tmp/passwd.ldif

[ root @server~ ]#   ./migrate_group.pl    /tmp/group   >   /tmp/group.ldif

 

Step-5  Upload ldif file into ldap server.

[ root @server~ ]#   ldapadd    -x    -D    "cn=Manager,dc=leolinux,dc=in"    -W    -f      /tmp/base.ldif 

[ root @server~ ]#   ldapadd    -x    -D    "cn=Manager,dc=leolinux,dc=in"    -W    -f      /tmp/passwd.ldif 

[ root @server~ ]#   ldapadd    -x    -D    "cn=Manager,dc=leolinux,dc=in"    -W    -f      /tmp/group.ldif 

 

Step-6   To test  uploaded user entry.

[ root @server~ ]#     ldapsearch    -x     -b     dc=leolinux,dc=in

 

Cheer !!