How to Change a USER and GROUP ID on Linux For All Owned Files

How to Change a USER and GROUP ID on Linux For All Owned Files

To change the user and group ID (UID and GID) of a user on a Linux system, as well as the ownership of all the files owned by that user, you can use the usermod command.

Here's an example of how to use usermod to change the UID and GID of the user jane to 1000 and 100, respectively:

refe‮ r‬to:lautturi.com
$ sudo usermod -u 1000 -g 100 jane

The -u option specifies the new UID, and the -g option specifies the new GID.

Note: You will need to have the necessary privileges to run the sudo command.

It's also a good idea to use the -R option to recursively change the ownership of all the files owned by the user. For example:

$ sudo chown -R jane:users /home/jane

This will change the ownership of all the files in the /home/jane directory (and all its subdirectories) to the user jane and group users.

Note: Changing the UID and GID of a user can have unintended consequences, so it's important to carefully consider the implications before making any changes. For example, some applications may rely on the UID and GID of a user to function properly, and changing these values may cause these applications to break. It's also a good idea to back up important data before making any changes.

Created Time:2017-10-28 21:38:57  Author:lautturi