Rename User in Linux
12 February 2025
Linux
CLI
You cannot be logged in as the current user you are renaming, so do one of the following...
- Use root account:
- Enable root (if not enabled) by setting password:
sudo passwd root
- Logout and login as root:
logout
- Use another sudo-enabled account:
- Logout and login with a sudo-enabled account:
logout
- Use sudo before the below commands or use
sudo su - to elevate
Replace oldname with your old username and newname with the new username…
- Rename the login username:
usermod -l newname oldname
- Update the home directory:
usermod -d /home/newname -m newname
- Update primary group:
groupmod -n newname oldname
- Rename the full name:
chfn -f "Full Name" newname
- Replace Full Name with the new full name
- Logout and login as new user:
logout
Disable root account (if you enabled it):
- Delete the password:
sudo passwd -d root
- Lock the account:
sudo passwd -l root
See More Posts