Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Changing a Linux account’s numeric UID or GID does not automatically update every file on the system. usermod updates eligible files in the user’s home directory when changing a UID, and groupmod updates primary-group membership when changing a GID; ownership elsewhere must be found and migrated separately. Plan the scope, stop the user’s processes, change the account records, then update and verify files by their old numeric IDs.

What a UID or GID change actually affects

Linux files record ownership as numeric user and group IDs. A displayed login or group name is resolved from account databases; changing a name is not the same as changing the numeric ID that files store. If an ID changes but file metadata does not, affected files can appear under an unexpected name—or as an unresolved numeric ID.

Operation Command What it updates automatically What needs separate attention
Change a user ID (UID) usermod -u NEW_UID LOGIN The user’s mailbox and eligible files in the home directory Files outside the home directory; scheduled jobs such as crontab and at files
Change a group ID (GID) groupmod -g NEW_GID GROUP Users whose primary group is the changed group Files still carrying the old GID that should belong to the group

These behaviors are documented in the usermod(8) manual and groupmod(8) manual. The commands change local account records; they are not a system-wide filesystem migration.

Before changing either ID

Record the current and intended identities

  • Write down the login name, current UID, current primary GID and group name, and the new UID and GID.
  • Confirm that the new IDs are not already assigned to another account or group. The manuals require IDs to be unique unless a non-unique option is deliberately used.
  • Define which filesystems and paths are in scope. Include relevant data volumes explicitly rather than assuming a scan of the root filesystem covers them.

Schedule a safe maintenance window

Stop services, sessions, and other processes running as the user before changing the UID. The usermod manual warns that the user must not be executing processes during a numeric UID change. Preserve a recoverable backup or snapshot of relevant data and account configuration so you can restore the prior state if the migration goes wrong.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Check who controls the identity

These commands are examples for local Linux account records. If the account is supplied through NIS, the usermod manual says the change belongs on the NIS server. LDAP, Active Directory, containers, user namespaces, NFS, and other network filesystems can have separate identity authorities or mappings; the local account manuals do not define one universal migration procedure for them.

Change the UID and GID records

Change the user ID

  1. Run the UID change with the account’s login name:

    sudo usermod -u NEW_UID LOGIN
  2. Replace NEW_UID and LOGIN with the intended numeric UID and login name. The command updates the mailbox and eligible files in the user’s home directory. There is a safety exception if the home directory’s owner UID differs from both the current and new UID; inspect the result rather than assuming every home file was changed.

  3. Plan to migrate files outside the home directory separately. The manual states: “The ownership of files outside of the user’s home directory must be fixed manually.”

    Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Change the group ID

  1. Run the group change with the group name:

    sudo groupmod -g NEW_GID GROUP
  2. Replace NEW_GID and GROUP with the target GID and group name. Users with that group as their primary group are updated in the account database.

  3. Find files that still carry the old GID and change only those that should continue to belong to this group. As the groupmod manual puts it: “Any files that have the old group ID and must continue to belong to GROUP, must have their group ID changed manually.”

If changing both IDs, keep both old numeric values recorded and plan the two account changes as part of one maintenance window. The manuals document UID and GID operations separately and do not prescribe one universal order for every setup.

Find files still using the old numeric IDs

Use numeric predicates so the search does not depend on how names resolve after the account change. For example, to search one filesystem starting at its root:

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
sudo find / -xdev -uid OLD_UID -print
sudo find / -xdev -gid OLD_GID -print

Replace the placeholders with the old numeric values. The -xdev option avoids crossing onto filesystems with a different device number. It is a scope limit, not evidence that all relevant files are on that filesystem. Run additional searches from the roots of included mounted filesystems, choosing traversal behavior intentionally. The find(1) manual documents numeric owner and group tests, as well as -nouser and -nogroup for files whose IDs do not match an account entry.

Review results before changing ownership

Inspect the inventory before migrating it, especially on a multi-user host. The old numeric ID might already have been assigned to another account or group, or some files may intentionally retain that ownership. A host-wide search can also encounter mounted storage, container data, and filesystems whose ownership is controlled by an external identity service.

Update ownership in the intended paths

After reviewing the search results, use a narrow path and numeric ownership operands. For example:

sudo find /srv/data -xdev -uid OLD_UID -exec chown NEW_UID {} +
sudo find /srv/data -xdev -gid OLD_GID -exec chown :NEW_GID {} +

These are illustrative command forms: replace the placeholders and path, and confirm the scope before running them. The first changes the user owner on matching files; the second changes the group owner. GNU chown accepts numeric IDs, as described in the chown(1) manual.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Do not assume every file matching an old UID should receive the new UID, or every file matching an old GID should receive the new GID. Preserve ownership belonging to other users and groups. If a file matches both old IDs, changing both fields may be appropriate; if it matches only one, change only that field. Choose symlink handling and filesystem traversal deliberately: recursive ownership operations and link behavior can have consequences. The chown(1) manual documents these behaviors.

Handle scheduled jobs and other ownership records

The usermod manual calls out crontab files and at jobs as ownership that must be corrected manually. Check these alongside service data and any other account-specific files outside the home directory; do not assume the account database change migrates them.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Verify the migration

  1. Confirm the account now has the intended UID and primary group, and confirm the group has the intended GID.

  2. Inspect representative files numerically, including home-directory contents, the mailbox, service data, scheduled jobs, and each filesystem included in the migration.

    Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  3. Repeat scoped searches for the old UID and GID. Investigate remaining matches rather than changing them automatically.

  4. Optionally search for unresolved ownership with find -nouser and find -nogroup. These can reveal IDs with no matching local account entry, but may also find intentional ownership managed by an external identity system.

Commands and behavior can vary with distribution version, filesystem, and identity architecture. The cited usermod manual identifies shadow-utils 4.19.0; other cited manuals and specifications were accessed on 2026-10-08. Treat the examples as Linux command patterns, and verify their behavior against the installed system’s manuals and identity setup.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.