# Map old LDAP users to new on server change

**URL:** <https://help.nextcloud.com/t/map-old-ldap-users-to-new-on-server-change/171038>\
**Category:** ℹ️ Support\
**Tags:** ldap\
**Created:** [September 27, 2023, 10:24am UTC](https://help.nextcloud.com/t/map-old-ldap-users-to-new-on-server-change/171038 "2023-09-27T10:24:27Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![stuart475898](https://help.nextcloud.com/letter_avatar/stuart475898/32/6_22734026db12803ebb3e059622ac3534.png) [@stuart475898](https://help.nextcloud.com/u/stuart475898)\
**Post date:** [September 27, 2023, 10:24am UTC](https://help.nextcloud.com/t/map-old-ldap-users-to-new-on-server-change/171038/1 "2023-09-27T10:24:27Z")

</div>

Hi everyone,

Currently using Active Directory as a user back end, but wish to move to LLDAP. I have LLDAP setup and working with Nextcloud, but users in LLDAP are treated as new in Nextcloud. Does anyone have any guidance how I can use LLDAP but maintain the user mapping? Presumably I need to update some anchor attribute in Nextcloud somewhere?

This article may have the answer for me, but disappointingly is behind a paywall - appears you _must_ be a customer to read it: [Migrating to another LDAP server](https://portal.nextcloud.com/article/Authentication/LDAP/Migrating-to-another-LDAP-server)

Thank you

---

<div class="post-metadata">

**Author:** ![stuart475898](https://help.nextcloud.com/letter_avatar/stuart475898/32/6_22734026db12803ebb3e059622ac3534.png) [@stuart475898](https://help.nextcloud.com/u/stuart475898)\
**Post date:** [September 28, 2023, 8:29pm UTC](https://help.nextcloud.com/t/map-old-ldap-users-to-new-on-server-change/171038/2 "2023-09-28T20:29:11Z")

</div>

I don’t know if this is safe or not, but I did the following to get this working without issue (apparently). Note that my install is small and at home so I just logged in with the duplicate accounts to get the appropriate `ldap_dn`/`directory_uuid`/`ldap_dn`/`ldap_dn_hash` values, but you could get these yourself from the new LDAP server to script this out (hash is S256). Credit to: [LDAP Migration with different DN - ℹ Support - Nextcloud community](https://help.nextcloud.com/t/ldap-migration-with-different-dn/88449). Users in the old and new LDAP server have the same username/uid/sAMAccountName/etc.

If the users on the new LDAP server have logged in, they will have accounts created in the `oc_ldap_user_mapping` table. We need to replace some values in the `direcotry_uuid` and `ldap_dn_hash` fields as they have `UNIQUE KEY` constraints - this step isn’t required if the users have not logged in from the new server:

`UPDATE oc_ldap_user_mapping SET directory_uuid = 'TEMP_<new ldap server directory_uuid>', ldap_dn_hash = '_<new ldap server ldap_dn_hash (remove first charater due to field length constraint)>' WHERE owncloud_name = 'erin_<random int for new directory user>';`

We can then populate the entries for the old LDAP server with the new server details:

`UPDATE oc_ldap_user_mapping SET ldap_dn = '<new ldap server dn>', directory_uuid = '<new ldap server directory_uuid>', ldap_dn_hash = '<new ldap server ldap_dn_hash>' WHERE owncloud_name = '<username>';`

---

<div class="post-metadata">

**Author:** ![wwe](https://help.nextcloud.com/user_avatar/help.nextcloud.com/wwe/32/72963_2.png) [@wwe](https://help.nextcloud.com/u/wwe)\
**Post date:** [December 14, 2024, 1:06pm UTC](https://help.nextcloud.com/t/map-old-ldap-users-to-new-on-server-change/171038/3 "2024-12-14T13:06:19Z")

</div>


