Migrating Users to a New Server

krowemoh

Nivethan

Posted on October 26, 2022

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 | tee โ€“ |egrep -f โ€“ /etc/shadow > shadow.bk
/bin/cp /etc/gshadow gshadow.bk
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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

๐Ÿ’– ๐Ÿ’ช ๐Ÿ™… ๐Ÿšฉ
krowemoh
Nivethan

Posted on October 26, 2022

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related

ยฉ TheLazy.dev

About