To change the username on Ubuntu, follow these steps carefully, as doing it incorrectly can cause login or permission issues. Here’s the safe way to do it from a terminal:
✅ Step-by-step: Change Username on Ubuntu
🛑 Important: You must not be logged into the account you’re trying to rename. Use another user account with
sudoprivileges or switch to a TTY (e.g.,Ctrl+Alt+F3) and log in as another user.
1. Log in as a different user (with sudo rights)
If you don’t have another user, create one temporarily:
sudo adduser tempadmin
sudo usermod -aG sudo tempadmin
Log out and log in as tempadmin.
2. Change the username
Replace oldusername with the current name and newusername with the desired name:
sudo usermod -l newusername oldusername
This changes the login name, but not the home directory.
3. Rename the home directory
sudo mv /home/oldusername /home/newusername
Then update the user’s home path:
sudo usermod -d /home/newusername -m newusername
4. Fix ownership of the home folder (just in case)
sudo chown -R newusername:newusername /home/newusername
5. Update display name (optional)
To change the “Full Name” shown in login screens, run:
sudo chfn -f "New Full Name" newusername
6. Reboot and test
sudo reboot
Log in as the new user.
7. (Optional) Delete the temp admin account
After confirming everything works:
sudo deluser tempadmin
sudo rm -r /home/tempadmin