What to do after moving servers, when user / group ids are unresolved
October 22nd, 2007
I have had several people write asking how to fix unresolved uid’s and gid’s after moving servers. That is, they moved hardware/operating system install and did not create the users and groups on the new host with the same id’s as the old host. I am presenting a resolution. The script when run on the old host will output a list of find commands which you can run on the new host. This script is only meant to run on Linux. The Solaris /AIX version’s of find do not support the options I need to perform this change safely.
Note: This script assumes that the old ids are not resolved on the new host. That is, all the old id’s do not resolve, accidentally, to users on the new host. If this is NOT the case, you can remove the -nouser and -nogroup find options. However, I would recommend running the script as is and then resolving any other issues by hand.
The process is as follows:
- Download the script to the old host.
- Run with the parameters needed and output redirected to a file.
- Copy output file to the new host and make executable.
- Execute as root.
Usage:
# ./fixNoUserGroupNames.sh
Usage: fixNoUserGroupNames.sh
-u uid do not alter users below this uid
-g gid do not alter groups below this gid
-p path start at this path
Sample run without redirecting to a file:
# ./fixNoUserGroupNames.sh -u 500 -g 500 -p /tmp/
#!/bin/bash
[[ "$USER" != "root" ]] && ( echo "must be root"; exit 1 )
[[ -d "/home/brock" ]] && chown brock /home/brock
find /tmp/ -nouser -uid 5022 -exec chown brock {} \;
[[ -d "/var/lib/nfs" ]] && chown nfsnobody /var/lib/nfs
find /tmp/ -nouser -uid 65534 -exec chown nfsnobody {} \;
[[ -d "/home/USER" ]] && chown USER /home/USER
find /tmp/ -nouser -uid 501 -exec chown USER {} \;
find /tmp/ -nogroup -gid 5022 -exec chgrp brock {} \;
find /tmp/ -nogroup -gid 65534 -exec chgrp nfsnobody {} \;
find /tmp/ -nogroup -gid 501 -exec chgrp USER {} \;
Running the script and resolving an unresolved uid and gid:
# ./fixNoUserGroupNames.sh -u 500 -g 500 -p /tmp/ >fix.sh
# chmod +x fix.sh
# ls -l /tmp/no-*
-rw-r--r-- 1 brock 5022 0 Oct 22 00:51 /tmp/no-group
-rw-r--r-- 1 5022 brock 0 Oct 22 00:51 /tmp/no-user
# ./fix.sh
# ls -l /tmp/no-*
-rw-r--r-- 1 brock brock 0 Oct 22 00:51 /tmp/no-group
-rw-r--r-- 1 brock brock 0 Oct 22 00:51 /tmp/no-user
Leave a Reply