Change user id and group id of user
Last Modified: March 1, 2020
If you run into an issue where you need to change the user id (uid) and group id (gid) of a user (<user>). Assume you want to change uid:gid from 1001:1001 (<old_uid>:<old_gid>) to 1000:1000 (<new_uid>:<new_gid>).
Steps by step guide
-
Login using a different user. If need
rootuser:ssh root@<hostname>. -
Kill all the process of
user. Find all process belonging to<user>usingps:ps aux | grep <user> -
Change
uidof<user>:usermod -u <new_uid> <user> -
Change
gidofuser:groupmod -g <new_gid> <user> -
Change ownership of all files from
<old_uid>:<old_gid>to<new_uid>:<new_gid>:find /parent/path/ \( -uid <old_uid> -o -gid <old_gid> \) \ -exec chown <new_uid>:<new_gid> {} \;Example:
find /home/lento \( -uid 1001 -o -gid 1001 \) \ -exec chown 1000:1000 {} \;