Linux How to change user UID and GID

I was running Debian for sometime and in Debian the UID starts at 1000. Now I moved to CentOS 6 and the UID starts from 500. Simply changing the UID/GID seemed like an quick way to get my file permission back in sync.

Here’s how to easily change the UID and GID for a user in Linux.

Check my current UID/GID
[root@atom ~]# id danesh
uid=500(danesh) gid=500(danesh) groups=500(danesh)

Change my UID to 1000
[root@atom ~]# usermod -u 1000 danesh

Check my UID/GID again. GID is still 500.
[root@atom ~]# id danesh
uid=1000(danesh) gid=500(danesh) groups=500(danesh)

Change the GID for my group.
[root@atom ~]# groupmod -g 1000 danesh

UID and GID now updated.
[root@atom ~]# id danesh
uid=1000(danesh) gid=1000(danesh) groups=1000(danesh)

This will update the files in your home directory with the correct UID/GID but anything outside you will have to do it yourself.

  • Franck

    Well groupmod manpage says that :

    Any files that have the old group ID and must continue to belong to GROUP, must have their group ID changed manually.

    So I guess files in home dir (and mailbox dir) will have correct UID but not correct GID…

    • Yup, you will have to update them manually,

© 2008-2012 The Danesh Project
Powered by Wordpress and made by Guerrilla. Hosted at ServerFreak