摘抄自stackoverflow

The Debian/Ubuntu policy is that if there is a user jim with user ID 1001, there is also a group jim with group ID 1001.

This solution also updates those group IDs.

  • Enable the root account: sudo passwd root If the user is logged in, then log out (also on virtual terminals) Go to VT1: Ctrl-Alt-F1 Log in as root and run this with the user name and old/new UID supplied:

  • put the information we need in variables username=... old_uid=id -u $username` # looks up current (old) uidnew_uid=…`

  • 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

  • Log out
  • Log in as $username
  • Disable the root account: sudo passwd -dl root

Published

Category

Linux