How to Change Username on Ubuntu 26.04

Changing a username on Ubuntu 26.04 is a straightforward task when you know the right commands. Whether you need to rename an account for organizational reasons or to correct a typo made during installation, Ubuntu 26.04 provides reliable command-line tools to user change ubuntu 26.04 safely. This tutorial walks you through every required step, including renaming the home directory and updating the primary group, so the account remains fully functional after the change.

In this tutorial you will learn:

  • Why the target account must be logged out before renaming
  • How to rename a user account with usermod -l
  • How to rename the home directory to match the new username
  • How to rename the primary group with groupmod -n
  • How to update the home directory path recorded in /etc/passwd
  • How to verify all changes applied correctly
Abstract illustration representing user account management on Ubuntu Linux with username and profile icons
Change a user account name on Ubuntu 26.04 using usermod, mv, and groupmod

Software Requirements

Software Requirements and Linux Command Line Conventions
Category Requirements, Conventions or Software Version Used
System Ubuntu 26.04 Resolute Raccoon
Software shadow-utils (usermod, groupmod – included by default)
Other Privileged access to your Linux system as root or via the sudo command. The account being renamed must not be currently logged in.
Conventions # – requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command
$ – requires given linux commands to be executed as a regular non-privileged user

TL;DR

TL;DR
To change a username on Ubuntu 26.04, log in as a different admin account, then run the following commands replacing oldname and newname accordingly.

Quick Steps to Change Username on Ubuntu 26.04
Step Command/Action
1. Rename the user account sudo usermod -l newname oldname
2. Rename the home directory sudo mv /home/oldname /home/newname
3. Update the home path sudo usermod -d /home/newname newname
4. Rename the primary group sudo groupmod -n newname oldname

Before You Begin

Before attempting a user change on Ubuntu 26.04, there is one critical requirement: you cannot rename an account that is currently logged in. The usermod command will refuse to proceed if the target user has active processes running. Therefore, you must perform all steps from a separate administrator account.

If your system only has one user account, you have two options. First, you can create a temporary administrator account, log out of the main account, log in as the temporary user, perform the rename, then delete the temporary account afterward. Second, you can boot into recovery mode which provides a root shell.

Additionally, list users on your system beforehand to confirm the exact current username, since a mismatch will cause the commands to fail.

IMPORTANT
All commands in this tutorial assume you are logged in as a different user with sudo privileges, not as the account you intend to rename.

Change the Username with usermod on Ubuntu 26.04

The primary tool for performing a user change on Ubuntu 26.04 is usermod, which modifies user account properties. The -l flag (lowercase L) specifies the new login name.

  1. Confirm the current username exists: Before making changes, verify the account is present in the system database.
    $ getent passwd oldname

    The command queries /etc/passwd and returns a line with the user’s UID, GID, home directory, and shell. If no output appears, the username does not exist and you should recheck the spelling.

  2. Rename the login name: Use usermod -l to assign the new username. Replace linuxconfig with your actual old username and linuxconfig-new with the desired new name.
    $ sudo usermod -l linuxconfig-new linuxconfig

    This command updates the login name field in /etc/passwd but does not rename the home directory or the primary group. Those steps follow separately.

Terminal output on Ubuntu 26.04 showing usermod -l renaming the linuxconfig account to linuxconfig-new, with getent passwd confirming the change
Using sudo usermod -l to change the login name, verified with getent passwd before and after

IMPORTANT
If you see the error usermod: user linuxconfig is currently logged in, log out of that account completely, including terminating any background sessions, before retrying.

Rename the Home Directory

After the login name change, the home directory still carries the old name. Consequently, when the user logs in, their shell environment may reference an incorrect path. Therefore, rename the directory to match the new username.

  1. Move the home directory: The mv command renames the directory in place without copying data, making it instantaneous regardless of directory size.
    $ sudo mv /home/linuxconfig /home/linuxconfig-new
  2. Update the recorded home path: The path stored in /etc/passwd still points to the old location. Use usermod -d to update it.
    $ sudo usermod -d /home/linuxconfig-new linuxconfig-new

    The -d flag sets the new home directory path. Note that the username argument is now the new name since the previous step already completed the rename.

    Terminal output on Ubuntu 26.04 showing mv renaming the home directory and usermod -d updating the home path, confirmed with getent passwd
    Using sudo mv and sudo usermod -d to rename the home directory and update its path in /etc/passwd

Rename the Primary Group

Ubuntu 26.04 creates a private primary group for each user account with the same name as the username. After a user change on Ubuntu 26.04, this group still holds the old name, which can cause confusion and inconsistency. Use groupmod -n to synchronize the group name.

  1. Rename the primary group: The -n flag specifies the new group name, followed by the current (old) group name.
    $ sudo groupmod -n linuxconfig-new linuxconfig

    This updates /etc/group and /etc/gshadow atomically. Additionally, any files owned by the GID retain their ownership since the GID number itself does not change, only the name.

Moreover, if the user belongs to supplementary groups, those memberships are unaffected by the username or primary group rename. You can confirm supplementary group membership with the groups command after the process is complete. You may also want to add the user to a group if additional permissions are required.

Verify /etc/passwd Is Consistent

At this point, all the individual changes have been applied. However, it is good practice to inspect /etc/passwd directly to confirm every field reflects the new username and home directory path before the user attempts to log in.

  1. Inspect the passwd entry: Query the updated record for the new username.
    $ getent passwd linuxconfig-new

    Expected output:

    linuxconfig-new:x:1000:1000:,,,:/home/linuxconfig-new:/bin/bash

    Confirm that the first field (login name) and the sixth field (home directory) both reflect the new name. The UID (third field) and GID (fourth field) remain unchanged.

Terminal output on Ubuntu 26.04 showing getent passwd confirming the linuxconfig-new account with updated username and home directory path
getent passwd linuxconfig-new confirming the consistent account entry after all rename steps

Verify the Username Change on Ubuntu 26.04

With all steps complete, perform a final verification to ensure the user change on Ubuntu 26.04 was fully successful.

  1. Check the group rename: Confirm the primary group name matches the new username.
    $ getent group linuxconfig-new

    The output should list the group name, GID, and group members.

  2. Confirm the home directory exists: Verify the renamed directory is accessible.
    $ ls -ld /home/linuxconfig-new

    The directory should be owned by the correct UID and GID.

  3. Test login: Switch to the renamed account using su to confirm the environment loads correctly.
    # su - linuxconfig-new

    Run whoami and echo $HOME inside the session to confirm both return the expected new values.

    $ whoami
    linuxconfig-new
    $ echo $HOME
    /home/linuxconfig-new

COMPLETED
The username has been successfully changed. The login name, home directory, and primary group are now consistent. The user can log in normally with the new credentials.

Terminal output on Ubuntu 26.04 showing getent group, ls -ld, su login, whoami, and echo $HOME all confirming the successful username change to linuxconfig-new
Final verification: group name, home directory ownership, and a successful login as linuxconfig-new all confirm the rename is complete

For additional reference on username and group management, consult the official Ubuntu usermod manual page.

Conclusion

Performing a user change on Ubuntu 26.04 involves four coordinated steps: renaming the login name with usermod -l, renaming the home directory with mv, updating the home path with usermod -d, and renaming the primary group with groupmod -n. Each step targets a different system file, and consequently all four must be completed to ensure a consistent and fully functional account. By following this tutorial, you have changed the username cleanly without affecting the user’s UID, GID, file ownership, or supplementary group memberships.

Frequently Asked Questions

  1. Can I change my own username while logged in? No. Ubuntu 26.04 prevents usermod from modifying an account that has active processes. You must log in as a different administrator account or use a root recovery shell to perform the rename.
  2. Will changing the username affect file ownership? No. File ownership on Linux is tracked by UID and GID numbers, not by name. Since usermod -l does not change the UID, all files owned by the account remain correctly owned after the rename. Only the display name in ls -l output changes once the system resolves the new name.
  3. Do I need to update any configuration files after changing the username? Possibly. Applications that store the username as a literal string in their configuration files (such as some SSH authorized_keys paths or cron jobs referencing /home/oldname) will need manual updates. Additionally, if the user has a custom sudoers entry referencing the old username, update /etc/sudoers with visudo accordingly.
  4. What is the difference between usermod -l and creating a new account? The usermod -l approach preserves the existing UID, GID, home directory contents, group memberships, and password hash. Creating a new account generates a new UID and requires manually migrating files and permissions, which is significantly more disruptive. Therefore, usermod -l is always preferred when you simply need to rename an existing account.