Rename user on Linux and Windows
5/15/2021, 12:29:40 PM
Recently I needed to rename my username on some Linux and Windows machines.
Here’re the right way to rename a user on those operating systems. (And correctly rename user home dir)
- Setup another admin account, or unlock root account
- Stop all systemd services running using that user
- Disable or remove all systemd services that run as that user
- Logout, then login with another admin account (or root)
- You must ensure that the user has NO running process
- Open terminal (replace $NEW_USER and $OLD_USER to your own need)
usermod --login $NEW_USER --move-home --home /home/$NEW_USER $OLD_USER
groupmod --new-name $NEW_USER $OLD_USER
- Login with that user. Done!
- You may need to:
- Modify ssh public key username
- Open cmd.exe
control userpasswords2, modify username in the pop-up window
- Go to
- Found the subdir whose
ProfileImagePathrecord contains your current home dir
- Edit this record’s value to your wanted home dir
- Go to
- Logout and login. Don’t worry if your user settings (eg. background image) and desktop file is missing!
- If your new home dir exists, delete it
- Rename your old home dir to your wanted home dir
- Logout and login. Done!
- You may need to
- Re-setup onedrive
- Re-install some apps installed in user’s AppData dir