Changing a username in Linux is a common system administration task, whether for renaming users, maintaining naming conventions, or fixing incorrect usernames. This guide covers multiple methods including usermod, manual system file updates, and GUI-based approaches for Ubuntu.
Method 1: Change Username Using usermod (Recommended)
The usermod command is the safest and most recommended way to change a username in Linux. It updates the username along with the home directory and associated metadata.
Most Linux distributions create a group with the same name as the user by default (using :contentReference[oaicite:0]{index=0}). So when you rename a user, you should also update the group name to maintain consistency.
Before proceeding, make sure you have appropriate privileges using sudo or root access. You can verify your permissions using this guide on checking sudo access.
Rename user and update home directory:
sudo usermod -l newuser -d /home/newuser -m olduserExplanation:
-l→ specifies the new username-d→ sets the new home directory path-m→ moves the existing home directory content to the new location
After renaming the user, update the group name (if it matches the old username):
sudo groupmod -n newuser olduserVerify the changes:
getent passwd newuser
id newuserWhat happens to file ownership?
- All files owned by the user are linked internally using UID (User ID), not the username.
- Since the UID remains unchanged, file ownership is automatically preserved.
- You do not need to manually update ownership for most files.
However, always verify critical directories:
ls -ld /home/newuserIf required, you can fix ownership manually:
sudo chown -R newuser:newuser /home/newuserFor more details on managing users, refer to:
Method 2: Rename User Manually (Advanced)
This method is useful when usermod cannot be used or when you need full control over how user details are updated. It involves manually modifying system files that store user and group information.
sudo cp /etc/passwd /etc/passwd.bak
sudo cp /etc/group /etc/group.bak
sudo cp /etc/shadow /etc/shadow.bakStep 1: Update /etc/passwd
The /etc/passwd file stores basic user information such as username, UID, home directory, and shell.
sudo vi /etc/passwdChange:
olduser:x:1000:1000:olduser:/home/olduser:/bin/bashTo:
newuser:x:1000:1000:newuser:/home/newuser:/bin/bashHere:
- Username is updated from
olduser→newuser - Home directory path is also updated
Step 2: Update /etc/group
The /etc/group file stores group information. If a group exists with the same name as the user, update it as well:
sudo vi /etc/groupChange any occurrence of olduser to newuser.
Step 3: Update /etc/shadow
The /etc/shadow file stores encrypted password and account-related details.
sudo vi /etc/shadowUpdate the username field from olduser to newuser while keeping the password hash unchanged.
Step 4: Rename home directory
After updating system files, rename the user’s home directory:
sudo mv /home/olduser /home/newuserFix ownership:
sudo chown -R newuser:newuser /home/newuserWhat happens to file ownership?
- Just like with
usermod, Linux tracks ownership using UID and GID, not usernames. - Since UID/GID are unchanged, most file ownership remains intact.
- However, after manual changes, it is recommended to verify and correct ownership where needed.
Check ownership:
ls -ld /home/newuserIf inconsistencies are found:
sudo chown -R newuser:newuser /home/newuserVerify the changes
id newuser
getent passwd newuserEnsure:
- Username is updated
- UID/GID remain unchanged
- Home directory path is correct
- Do not perform these changes while logged in as the target user
- Always use root or another sudo-enabled account
- Incorrect edits in
/etc/passwdor/etc/shadowcan break login functionality
For safer alternatives, consider using the usermod command as explained in Method 1.
Method 3: Change Username in Ubuntu (GUI Method)
This method applies only to systems running GNOME desktop (default in Ubuntu Desktop). It will not work on server editions or other desktop environments like XFCE or KDE.
Steps:
- Go to Settings → Users
- Unlock with administrator password
- Create a new user with desired username
- Transfer files from old user
- Delete old user
Alternatively, use gnome-control-center:
gnome-control-center users- GUI method does not directly rename the user
- It creates a new user instead
Method 4: Rename User in Active Session (Workaround)
Linux does not allow renaming a user while they are logged in. Attempting this results in:
usermod: user olduser is currently used by processWorkarounds:
Kill active user processes:
sudo pkill -u olduserOr:
sudo killall -u olduserThen run:
sudo usermod -l newuser -d /home/newuser -m olduserBetter approach:
sudo rebootLog in as root or another user, then perform the rename operation.
Verify after rename:
id newuserSummary
Switching to GNOME on Linux depends on whether it is already installed and which desktop environment is currently active. You can quickly verify your current desktop using environment variables like XDG_CURRENT_DESKTOP and switch to GNOME from the login screen if it is available.
If GNOME is not installed, you can install it using your package manager and set it as the default session using system tools like update-alternatives. However, for most system administration tasks (such as user management), using terminal-based commands is preferred over GUI tools.
Official Documentation
Refer to the following official resources for more details:
- GNOME desktop introduction (Ubuntu Official Docs)
- Ubuntu graphical environments overview
- GNOME Control Center documentation
- gnome-control-center man page
These documents provide deeper insights into GNOME usage, configuration, and system integration.










