Code Yarns ‍👨‍💻
Tech BlogPersonal Blog

How to change UID and GID

📅 2017-Jun-27 ⬩ ✍️ Ashwin Nanjappa ⬩ 🏷️ gid, uid, usermod ⬩ 📚 Archive

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

© 2023 Ashwin Nanjappa • All writing under CC BY-SA license • 🐘 Mastodon📧 Email