# Import LDAP users & get rid of LDAP

**URL:** <https://help.nextcloud.com/t/import-ldap-users-get-rid-of-ldap/56629>\
**Category:** ℹ️ Support\
**Tags:** ldap\
**Created:** [July 14, 2019, 11:41am UTC](https://help.nextcloud.com/t/import-ldap-users-get-rid-of-ldap/56629 "2019-07-14T11:41:01Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Niols](https://help.nextcloud.com/user_avatar/help.nextcloud.com/niols/32/16498_2.png) [@Niols](https://help.nextcloud.com/u/Niols)\
**Post date:** [July 14, 2019, 11:41am UTC](https://help.nextcloud.com/t/import-ldap-users-get-rid-of-ldap/56629/1 "2019-07-14T11:41:01Z")

</div>

Hello there,

* * *

_TL;DR: I would like to convert my LDAP users to regular users and drop the LDAP backend. I am looking for an automated way to do that. I am not afraid of scripting some stuff to do that._

* * *

I have been using Nextcloud for a while now and I love it even more every day. A few years ago, I set up a LDAP server and configured Nextcloud to use it as a backend to provide users. It worked well for a while. However, with time, we closed the other services we used and now only Nextcloud still requires the LDAP.

I would like to drop the dependency in LDAP but keep my users. That would mean import the LDAP users as regular Nextcloud users, keeping their data. I’m OK with:

- losing the passwords. Nextcloud doesn’t know them anyway. And there is the password recovery function;
- loosing the shares. It’s a bit annoying, but recreating them isn’t that hard.

I was thinking about something like:

- save the files;
- save the list of usernames & email addresses;
- drop LDAP and the associated users;
- batch create users with the saved usernames & email addresses;
- move the old users files to the newly created users;
- rescan the files.

However, there might be a better way (is there?) and I should probably take care of calendars, contacts & tasks.

Any help would be greatly appreciated!

— Niols

* * *

Software & versions:

- _Nextcloud_ 16.0.3
- _Debian_ 10 (Buster), upgraded from 9 (stretch)
- _nginx_ 1.14.2 (from APT repositories)
- _PHP_ 7.3 (from APT repositories)
- _MariaDB_ 15.1 (from APT repositories)

---

<div class="post-metadata">

**Author:** ![KarlF12](https://help.nextcloud.com/user_avatar/help.nextcloud.com/karlf12/32/46873_2.png) [@KarlF12](https://help.nextcloud.com/u/KarlF12)\
**Post date:** [July 14, 2019, 4:15pm UTC](https://help.nextcloud.com/t/import-ldap-users-get-rid-of-ldap/56629/2 "2019-07-14T16:15:22Z")

</div>

I would encourage you to keep and integrate you LDAP, but to your question: I think what you are looking for is going to fall under the occ command which allows CLI management of Nextcloud.

---

<div class="post-metadata">

**Author:** ![yourcloudasia](https://help.nextcloud.com/user_avatar/help.nextcloud.com/yourcloudasia/32/8124_2.png) [@yourcloudasia](https://help.nextcloud.com/u/yourcloudasia)\
**Post date:** [July 15, 2019, 5:32am UTC](https://help.nextcloud.com/t/import-ldap-users-get-rid-of-ldap/56629/3 "2019-07-15T05:32:49Z")

</div>

Another option: install and migrate LDAP to your Nextcloud server and keep the LDAP dependency. It should be a lot less work, and you can continue to manage the LDAP directory using your existing tools. Running OpenLDAP should use a minimal amount of memory, and gives you a more flexible authentication solution if you want to change this again in the future.

---

<div class="post-metadata">

**Author:** ![budy](https://help.nextcloud.com/user_avatar/help.nextcloud.com/budy/32/697_2.png) [@budy](https://help.nextcloud.com/u/budy)\
**Post date:** [July 15, 2019, 5:41pm UTC](https://help.nextcloud.com/t/import-ldap-users-get-rid-of-ldap/56629/4 "2019-07-15T17:41:16Z")

</div>

I have moved some of my LDAP users to regular ones, by simply creating a new local user in NC and then use the cli tool to migrate all dara of my LDAP user account over to the new local user. This successfully moved all data and even pertained all shares, either received or granted, for the new local user account.

---

<div class="post-metadata">

**Author:** ![Niols](https://help.nextcloud.com/user_avatar/help.nextcloud.com/niols/32/16498_2.png) [@Niols](https://help.nextcloud.com/u/Niols)\
**Post date:** [July 21, 2019, 7:53pm UTC](https://help.nextcloud.com/t/import-ldap-users-get-rid-of-ldap/56629/6 "2019-07-21T19:53:18Z")

</div>

I would really like to get rid of LDAP. Not really for speed or memory usage (although having the authentication backend and Nextcloud on the same machine will clearly speed things up) but rather because I’m tired of maintaining too many (in my opinion) things.

Being able to create regular users and then migrate information from LDAP users to regular seems good to me. But I couldn’t see anything in the `occ` command about migrating data from one user to an other. Did I miss it?

---

<div class="post-metadata">

**Author:** ![budy](https://help.nextcloud.com/user_avatar/help.nextcloud.com/budy/32/697_2.png) [@budy](https://help.nextcloud.com/u/budy)\
**Post date:** [July 21, 2019, 8:26pm UTC](https://help.nextcloud.com/t/import-ldap-users-get-rid-of-ldap/56629/7 "2019-07-21T20:26:49Z")

</div>

This is the command you’re looking for:

```
sudo -u www-data php ./occ files:transfer-ownership [--path PATH] [--] <source-user> <destination-user>
```

---

<div class="post-metadata">

**Author:** ![Niols](https://help.nextcloud.com/user_avatar/help.nextcloud.com/niols/32/16498_2.png) [@Niols](https://help.nextcloud.com/u/Niols)\
**Post date:** [July 21, 2019, 8:47pm UTC](https://help.nextcloud.com/t/import-ldap-users-get-rid-of-ldap/56629/8 "2019-07-21T20:47:19Z")

</div>

Oh, nice, I didn’t think that I could find that there. I guess I can use:

```
./occ dav:move-calendar

```

for calendars. But I can’t find a similar command for addressbooks. Or are these being taken care of by `files:transfer-ownership`? (Probably not.)

---

<div class="post-metadata">

**Author:** ![budy](https://help.nextcloud.com/user_avatar/help.nextcloud.com/budy/32/697_2.png) [@budy](https://help.nextcloud.com/u/budy)\
**Post date:** [July 22, 2019, 6:37am UTC](https://help.nextcloud.com/t/import-ldap-users-get-rid-of-ldap/56629/9 "2019-07-22T06:37:26Z")

</div>

When I used the files:transfer-ownership command, my new local user account also got the calendar from the ldap account I wanted to get rid of.

---

<div class="post-metadata">

**Author:** ![Niols](https://help.nextcloud.com/user_avatar/help.nextcloud.com/niols/32/16498_2.png) [@Niols](https://help.nextcloud.com/u/Niols)\
**Post date:** [July 27, 2019, 1:49pm UTC](https://help.nextcloud.com/t/import-ldap-users-get-rid-of-ldap/56629/10 "2019-07-27T13:49:52Z")

</div>

I just gave it a try. Files are transferred to a directory “transferred from […]”. Calendars and contacts are not transferred. I can probably move calendars using `dav:move-calendar`. But I don’t know how I could move contacts. Any idea?

---

<div class="post-metadata">

**Author:** ![Niols](https://help.nextcloud.com/user_avatar/help.nextcloud.com/niols/32/16498_2.png) [@Niols](https://help.nextcloud.com/u/Niols)\
**Post date:** [January 11, 2020, 5:29pm UTC](https://help.nextcloud.com/t/import-ldap-users-get-rid-of-ldap/56629/11 "2020-01-11T17:29:32Z")

</div>

_Edit: cleanup instructions and add handling of groups._

I finally took some time to explore this issue. It turns out I got the rather simple following solution working: In the MySQL database, I created one new user per LDAP user **with the same uid**. I then disabled the LDAP app. This works because all the tables then refer to the uid that remains defined.

Potentially annoying consequences can be:

- that this solution relies directly on the layout of MySQL tables and is thus **not stable** ,

- that the `uid` used in the database is not necessarily the one one had to enter to connect (in my case, it wasn’t an issue),

- that the users loose their passwords (as it is never imported from LDAP). I decided to tell them in advance that they would have to use the “forgotten password” functionality, but that implies having a working e-mail configuration.

* * *

**This is very experimental and might very well not work for other versions of Nextcloud!** But it did work for me and version 17.0.0.

This obviously should occur in prod only after some testing on a safe copy of the targetted instance.

Here goes:

1. Turn on maintenance mode.  
_(CLI)_ `php occ maintenance:mode --on`

2. Check for incoming trouble.

3. Import users and groups

4. Disable LDAP.  
_(CLI)_ `php occ app:disable user_ldap`

5. Cleanup.

6. Turn off maintenance mode  
_(CLI)_ `php occ maintenance:mode --off`

---

<div class="post-metadata">

**Author:** ![hashworks](https://help.nextcloud.com/letter_avatar/hashworks/32/6_449c533f586939b6e5f246632a46421f.png) [@hashworks](https://help.nextcloud.com/u/hashworks)\
**Post date:** [March 23, 2023, 6:13pm UTC](https://help.nextcloud.com/t/import-ldap-users-get-rid-of-ldap/56629/12 "2023-03-23T18:13:57Z")

</div>

This still works with NC 25, but:

> [@Niols](#):
>
> Create one normal user per LDAP user.  
> _(SQL)_ `INSERT INTO oc_users (uid, uid_lower) SELECT owncloud_name, owncloud_name FROM oc_ldap_user_mapping`

This will not work if `owncloud_name` isn’t actually lowercase. Make sure of it using the following:  
_(SQL)_ `INSERT INTO oc_users (uid, uid_lower) SELECT owncloud_name, LOWER(owncloud_name) FROM oc_ldap_user_mapping`

---

<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 4, 2024, 10:06am UTC](https://help.nextcloud.com/t/import-ldap-users-get-rid-of-ldap/56629/13 "2024-12-04T10:06:04Z")

</div>


