Wednesday | 28 FEB 2024
[ previous ]
[ next ]

Migrating Users to a New Server

Date: 2022-10-26
Tags:  cheatsheet

Notes on migrating users to a new server.

We can use awk to filter the user files, we are splitting on ':' and checking the 3rd field, the user id. We don't want to bring over the system users which are usually at the top. I chose 200 based on my experience at work.

awk -F: '($3>=200) && ($3!=65534)' /etc/passwd > passwd.bk
awk -F: '($3>=200) && ($3!=65534)' /etc/group > group.bk
awk -F: '($3>=200) && ($3!=65534) {print $1}' /etc/passwd | grep -E -f - /etc/shadow > shadow.bk
/bin/cp /etc/gshadow gshadow.bk

The below commands will be run on the new machine once the backup files have been moved over.

cat passwd.bk >> /etc/passwd
cat group.bk >> /etc/group
cat shadow.bk >> /etc/shadow
/bin/cp gshadow.bk /etc/gshadow

Now we should be able to login with an existing user to make sure everything is working.

65534 is nfsnobody on rhel 7.4 and so we need to ignore that user.