Musings of an anonymous geek

March 5, 2007

Migrate a NIS password map to LDAP… FAST

Filed under: Scripting,Sysadmin,Technology — m0j0 @ 4:03 pm

I came across this awk hack in an old code repository today. I slapped it together a couple of *years* ago now, and it was never really worthy of being distributed for general use. However, if you’re like me and never made friends with the PADL migration tools and all you need is a quick way to convert a password map, maybe you can use this. If you need to convert a different map, you can use this as a starting point.
If you saved this as ‘nis2ldap’, you’d call it like this:

ypcat passwd | ./nis2ldap > users.ldif

users.ldif, then, would be your new ldif file, hopefully ready to be imported into your LDAP directory. It shouldn’t matter if you use Fedora Directory Server, Novell eDirectory, or OpenLDAP as long as the schema you’re using in your LDIF is supported by the server.


awk -F: '{
                print "dn: cn="$1",ou=People,dc=mydomain,dc=com"
                print "objectClass: top"
                print "objectClass: person"
                print "objectClass: organizationalPerson"
                print "objectClass: inetOrgPerson"
                print "objectClass: posixAccount"
                print "objectClass: inetLocalMailRecipient"
                print "objectClass: shadowAccount"
                print "uid: "$1
                gfields = split($5,gecos,",")
                namefield = split(gecos[1], fullname, " ")
                print "sn: " fullname[namefield]
                print "givenName: "fullname[1]
                print "cn: " $1
                print "userPassword: {crypt}"$2
                print "loginShell: "$7
                print "uidNumber: "$3
                print "gidNumber: "$4
                print "homeDirectory: "$6
                print "gecos: "$5
                print "mail: "$1""
                print "displayName: " gecos[1]
                print ""

See? You don’t really need 20 different perl scripts to do this!
Happy Monday 🙂

Technorati Tags: , , , , , ,

Social Bookmarks:



  1. […] around on the web. I was looking for a simple way to migrate an NIS+ passwd file to LDAP config and this is what I found. Unfortunately, when I went to cut and paste it into a script on my server, I realized it had a […]

    Pingback by Cool Breeze » Quick NIS passwd to LDAP script — April 14, 2008 @ 11:04 pm | Reply

  2. ecoloblue molecule

    Migrate a NIS password map to LDAP… FAST | Musings of an anonymous geek

    Trackback by ecoloblue molecule — January 11, 2015 @ 2:32 pm | Reply

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

Blog at

%d bloggers like this: