How to rename username in Nextcloud


Is there option to rename username in Nextcloud without loosing anything ?

Background is, We are migrating to LDAP as a SSO, we have multiple platform on which we will use ldap user to login with SSO. We need to migrate all users of all platorms (taiga, gitlab, nextcloud etc) to LDAP authentication. Demonstration has been made on backup environment.

Only users of Nextcloud have different username comparative to other platform, for example a user “A test” having username atest in all platforms but in Nextcloud he has username testa. Now we need to rename testa to atest. Is it possible? or any workaround?

NC: 24.0.7
OS: Debian 11

Please advice.

The username itself is used as a key in many tables, so you can’t easily change it. So the tips often referred to using just a different display name and the mail address, and to keep the real username as a “hidden” user-id.

However, LDAP users are managed separately, how that works and how they manage conflicts:

Not sure if their enterprise-service has something more sophisticated.

Other idea:
Create a new user, then transfer the data from the existing user to this new one. Not sure if that works well with all the apps. But in theory it would be a nice thing to be able to migrate a user with all its data to a different instance (or just a different user id).

Okay, will user get chat history back if create a new user and transfer files ownership etc.

I don’t think so, as far as I know this functionality only transfers files and shares, talk messages would thus be lost.

@Daphne is right, this won’t work. Work for transfer ownership is on the todo list, but will not work for 1-1 conversations:

I am in search of workaround of renaming username. This is very needful in my case almost all local users have been migrated to LDAP, only few users whose local username does not match with other platform.

Fyi, local user migration to LDAP is also not possible officially, but making changes in oc_users made it work. Means this is workaround and worked perfectly

Similarly there must be workaround for renaming username. I tried renaming from oc_user table then it just created new user.

please advice

the issue with this is that renaming usernames is not supported due to various technical considerations. This is also documented:

Thank you.

Yes i previously looked into this. Purpose of posting here to find workaround. May be some of the people among us wanted this. So with discussion we can make it possible.

My another test:

I have renamed uid and lower uid in oc_user, then rename data directory of user in data/ with similar to that new username

When i logged in with new renamed user id, all my data available. Issue is that my chat history is not there. Further looking into it.

Lets work together to make it possible, it will help others.

1 Like

So here is workaround

Just writing here steps for future what did to accomplish this:

We had a username “Xyz Test” which we require to rename to xtest for example.

  1. Renamed user data directory “Xyz Test” to xtest
  2. Run command find . -name “Xyz Test” in nextcloud root directory, and renamed all found directories to xtest
  3. Took backup nextclouddb in .sql file
  4. opened nextclouddb.sql file in nano editor and replaced all entries “Xyz Test” by xtest in one go by using feature of nano editor.
  5. Saved the file and exit
  6. Restored nextclouddb.sql
  7. sudo -u www-data php occ files:scan userid or sudo -u www-data php occ files:scan --all

Now Xyz Test user can login with xtest. All files and talk conversation are there

This is the story :slight_smile:

1 Like


It Worked very well when tested over a test user.

Now I have tested it over a active user in backup environment. Asked him to test all things. The files name that contains username now shows as with new Filename (with new username string) in Nextcloud (there are 1000s of files that are not required to rename) it is because i guess database pointer updated new username in filename (only those files name that contain Username) .

Let me clear, For example Tom is user we renamed Tom username with Toma. Those files that contains Tom in file name also showing as Toma in nextcloud and they do not able to load or Download. It gives internal server error. For example Tom_Certificate.pdf showing as Toma_certificate.pdf. Now there are 1000s of file in specific user directory if they all required to rename it will be nearly impossible.

Hope that i have cleared my problem.

Any advice would be very much welcome.

Hey there. Running occ files:scan --all would fix this for you. You’ve changed the FILES app database entries but not the filenames themselves. files:scan will get everything back in working order.

1 Like

Great thank you, i will try that back to here

If theres ALOT of files, it might take awhile for the occ command to complete. Let us know how you get on here on the forum : )

Just tested its working

sudo -u www-data php occ files:scan userid

Fixed the issue

Thanks a lot. So username rename is possible in nextcloud by this work around

Yeah. And if you didn’t change the oc_filecache table in the database you wouldn’t need the files:scan step. You can files:scan -all as well, if you’ve got a lot of users and don’t want to do each one by hand

Yes right thank you. For now we had tested it on two users, so to save the time just put username instead -all

Your very welcome

1 Like

Rescanning is not really good, that means that users have to resync their files!

But there are more problems if you just go through the whole sql file. If you have a user Tom and a user Tomato, you start to rename Tom to Toma, this way you also rename Tomato to Tomaato. And if you have other database entries with “Tom”, it will rename everything…

1 Like

Yes your very right. I was just helping a man after he had kooked his SQL database by hand with nano. He got a lot of respect for pulling that off.

Theres no work around for Russian roulette my friend