Skip to content

Instantly share code, notes, and snippets.

@danielm
Created December 11, 2021 17:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danielm/1714ae5f32480d43e09294832a09b293 to your computer and use it in GitHub Desktop.
Save danielm/1714ae5f32480d43e09294832a09b293 to your computer and use it in GitHub Desktop.
Change Unix/Linux UID
#
# THIS IS EXTREMLY RISKY TO RUN IF U DONT KNOW WHATS GOING ON
# DONT JUST COPY PASTE STUFF, READ IT, UNDERSTAND WHATS GOING SO IT WONT BREAK YOUR USER/SYSTEM
#
# put the information we need in variables
username=danielmorales
old_uid=`id -u $username` # looks up current (old) uid
new_uid=1000
# update the user ID and group ID for $username
usermod -u $new_uid $username
groupmod -g $new_uid $username
# update the file ownerships
# NB: you cannot combine the next two chowns, or files where
# only the uid xor the gid matches won't be updated
chown -Rhc --from=$old_uid $new_uid / # change the user IDs
chown -Rhc --from=:$old_uid :$new_uid / # change the group IDs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment