You can make a difference in the Apple Support Community!

When you sign up with your Apple Account, you can provide valuable feedback to other community members by upvoting helpful replies and User Tips.

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

changing account name and home directory without losing user preferences

I followed this article (https://support.apple.com/en-us/HT201548) and lost all my preferences, as I understand it these are stored in ~/Library/Preferences/ e.g. dock applications were gone, all my general preferences like mouse scroll direction and a nasty side effect lots of apps failed to open. Is there a way to do this without avoiding this loss. I am a developer so happy with CLI tools etc. permissions looked fine but perhaps the preferences were automatically moved or cleared during the rename process?


I want to rename my account and home dir without losing my preferences or creating a new user and manually having to install all my apps and move data.

Posted on Dec 16, 2021 5:40 AM

Reply
Question marked as Top-ranking reply

Posted on Dec 21, 2021 1:46 AM

So to answer my own question, and maybe help someone else. I did a slightly more involved process and got what looks like most things working. This is going to be a bit more of a developer solution I'm afraid though:


what finally worked for me was to follow basically the article, but then recursively chown files and folders still owned by the previous user. I used a script which recursively checks a directory and contents if the user is the old one and if so change (chown) to the new one, but there is an additional step I had first to disable csrutil (system integrity check) to achieve this since some things a locked/restricted, and you have to do that in recovery mode. I'll post the bash script and the directories I ran this on.


1) reboot into a different admin user from the one you are changing, rename the home directory and then the user account as specified in the apple article.


2) reboot into recovery mode, open terminal type: csrutil disable (will ask you for a user and a password, use the admin one where you are going to perform this)


3) run the bash script below on the following directories (script will take a while depending on how many files etc. are in there)


  • /Applications
  • /Library
  • /private/var
  • /usr/local


create this bash file (I use nano as it's built in), so on the command line (terminal)

something like: touch doit.bash

then: sudo nano doit.bash

then copy and paste the code below into nano with the changed values, you will need to update the script for each directory you want to run it on.

save the script and exit nano.

To be able to execute the script you will need to then: chmod +x doit.bash

then run the script with: ./doit.bash


#!/bin/bash

olduser=oldusername # replace oldusername with your old username
newuser=newusername # replace newusername with your new username
dir=thedir # replace thedir with the directory you want to run through e.g. /Applications

find $dir | while read filename
do
  owner=$(stat "$filename" | cut -d ' ' -f 5)
  if [ $owner == $olduser ]
  then
    chown $newuser $filename
  fi
done



4) Reboot into recovery, and open terminal and re-enable csrutil with: csrutil enable


5) reboot into your changed user, hopefully all preferences etc are preserved.


I really don't get why apple doesn't automate this process.


anyway good luck, hopefully helps someone else!


Similar questions

7 replies
Question marked as Top-ranking reply

Dec 21, 2021 1:46 AM in response to sirg45

So to answer my own question, and maybe help someone else. I did a slightly more involved process and got what looks like most things working. This is going to be a bit more of a developer solution I'm afraid though:


what finally worked for me was to follow basically the article, but then recursively chown files and folders still owned by the previous user. I used a script which recursively checks a directory and contents if the user is the old one and if so change (chown) to the new one, but there is an additional step I had first to disable csrutil (system integrity check) to achieve this since some things a locked/restricted, and you have to do that in recovery mode. I'll post the bash script and the directories I ran this on.


1) reboot into a different admin user from the one you are changing, rename the home directory and then the user account as specified in the apple article.


2) reboot into recovery mode, open terminal type: csrutil disable (will ask you for a user and a password, use the admin one where you are going to perform this)


3) run the bash script below on the following directories (script will take a while depending on how many files etc. are in there)


  • /Applications
  • /Library
  • /private/var
  • /usr/local


create this bash file (I use nano as it's built in), so on the command line (terminal)

something like: touch doit.bash

then: sudo nano doit.bash

then copy and paste the code below into nano with the changed values, you will need to update the script for each directory you want to run it on.

save the script and exit nano.

To be able to execute the script you will need to then: chmod +x doit.bash

then run the script with: ./doit.bash


#!/bin/bash

olduser=oldusername # replace oldusername with your old username
newuser=newusername # replace newusername with your new username
dir=thedir # replace thedir with the directory you want to run through e.g. /Applications

find $dir | while read filename
do
  owner=$(stat "$filename" | cut -d ' ' -f 5)
  if [ $owner == $olduser ]
  then
    chown $newuser $filename
  fi
done



4) Reboot into recovery, and open terminal and re-enable csrutil with: csrutil enable


5) reboot into your changed user, hopefully all preferences etc are preserved.


I really don't get why apple doesn't automate this process.


anyway good luck, hopefully helps someone else!


Dec 16, 2021 5:53 AM in response to sirg45

Did you create a new admin user in order to change the name? If you didn’t, you normally will lose admin capability.


If you lost your preferences, is it still pointing to your new home folder, or did it create a new one in /Users? It sounds like the path change didn’t take.


Also, did you move the old home to the new location? Changing the path doesn’t move the old home.

changing account name and home directory without losing user preferences

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.