I need some help changing user GID and UID in Ubuntu 13.04 in order to map an NFS mount, it is my understanding that these need to be the same on local machine as well as LDAP side.

Thank you.


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.


  • Recently tried this, apparently usermod reassigns the rights to your home directory to the new UID for you, at least in Linux Mint Rebecca – TheFiddlerWins Aug 18 '15 at 17:58

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.