[CentOS] UID/GID CentOS 6 to CentOS 7

Thu Oct 22 13:09:28 UTC 2020
Simon Matter <simon.matter at invoca.ch>

>> Hi,
>> we are upgrading some servers from C6 to C7 with a lot of user accounts
>> on them (UID>=500).
>> CentOS 7 has MIN_UID/MIN_GID 1000, Centos 6 has 500 in login.defs.
>> Can I change in /etc/login.defs MIN_UID/MIN_GID to 500 for C7? So I
>> could just grep the users out from passwd/shadow/group files and append
>> them to the Centos7 passwd/shadow/group files.
>> Can this do any damage to CentOS7 later on? Thinking about updates....
> When I did an upgrade from CentOS 5 to 7 I found that even a standard
> install of CentOS 7 already used a number of GIDs in the range of 500-999.
> In the end I decided to rearrange all users to new UIDs/GIDs and converted
> all storage with a script.
> The tricky part was to find a way which doesn't take ages to convert
> storage. Doing so with find.... wasn't possible for performance reasons.
> Attached script was used to convert every user. It was the fastest way I
> found. The script was started in background for every user.

Looks like attachments are stripped from the mail, so here is the script


if (( $# < 3 )); then
  echo "Usage: $0 <username> <new uid> <dir> [<dir>...]"
  echo "Example: $0 user1 1000 /tmp /etc /usr /opt /var /home"
  exit 1


shift 2

OLD_UID=$(id -u $USR)
OLD_GID=$(id -g $USR)

if [[ -z "$NEW_GID" ]]; then

echo "modifying user $USR ids ${OLD_UID}:${OLD_GID} ->

# Note: usermod changes ownership of at least $HOME and
groupmod -g $NEW_GID $USR
usermod -u $NEW_UID -g $USR $USR

chown --changes --silent --no-dereference --preserve-root --recursive
--from=:${OLD_GID} :${NEW_GID} $DIRS
chown --changes --silent --no-dereference --preserve-root --recursive
--from=${OLD_UID}   ${NEW_UID} $DIRS