DEV Community

Nivethan
Nivethan

Posted on • Originally published at nivethan.dev

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.

Top comments (0)