How to change UID and GID

You may sometimes want to change the UID (user ID) and GID (group ID) of your username. This can be done easily in Linux in two steps: change the ID and then change the file owner of all files with the old IDs.

Change UID

For example, to change UID of joe from 1000 to 9000:

$ sudo usermod -u 9000 joe
$ sudo find / -user 1000 -exec chown -h 9000 {} \;

Change GID

For example, to change GID of joe from 2000 to 8000:

$ sudo groupmod -g 8000 joe
$ sudo find / -group 2000 -exec chgrp -h 8000 {} \;
$ sudo usermod -g 8000 joe

If you get any errors, please remember to logout of your desktop and kill any processes that are holding on to your username. It is best to just run these commands from a virtual terminal like Ctrl + Alt + F1.

Tried with: Ubuntu 16.04

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.