How to change user GID and UID in Ubuntu 13.04?

Solution 1:

WARNING: Messing with UIDs and GIDs can be hazardous to your sanity if it all goes pear-shaped. Using any of the scripts that follow is done entirely at your own risk.

Here are the commands to run as root to change the UID and GID for a user. Simply change the variables in angled brackets to match your settings:

usermod -u <NEWUID> <LOGIN>    
groupmod -g <NEWGID> <GROUP>
find / -user <OLDUID> -exec chown -h <NEWUID> {} \;
find / -group <OLDGID> -exec chgrp -h <NEWGID> {} \;
usermod -g <NEWGID> <LOGIN>

usermod and groupmod simply change the UID and GID for their respective named counterpart usermod also changes the UID for the files in the homedir but naturally we can’t assume the only place files have been created is in the user’s homedir.

The find command recurses the filesystem from / and changes everything with UID of OLDUID to be owned by NEWUID and them changes the group for the files owned by the OLDGROUP.

The final usermod command changes the login group for the user.

Source:

  • Changing UIDs and GIDs for a user