How to move user account from Linux server to another server

This article will show you how to cleanly move user accounts from one Linux server (such as Redhat or CentOS) to another server and all related files.

The user can be a person, an account tied to a physical user, or an account that exists for a specific application. Linux users can be divided into two types, one is a system user, and the other is a normal user or application user. The default ID value of system users is 0 to 499, and the ID value of ordinary users is 500 to 60,000.

First, we must understand the configuration files related to user accounts.

• / etc / passwd contains information about users. • / etc / passwd contains information about the group. • / etc / shadow contains the user’s encrypted password. • / var / spool / mail contains user mail, which is stored in this file. • / home / user contains the user’s home directory, so it may contain user data.

When moving users from one server to another, the above files are very important, so we need to back up the above files.

#mkdir accountbackup # Export UGIDLIMIT = 500 # awk -v LIMIT = $ UGIDLIMIT-F: ‘($ 3> = LIMIT) && ($ 3! = 65534)’ / etc / passwd> / root / accountbackup

The above command will copy the account filtered by / etc / passwd file to /etc/accountbackup/passwd.olds.

Similarly, copy the selected group to the / etc / group file:

#Awk -v LIMIT = $ UGIDLIMIT -F: ‘($ 3> = LIMIT) && ($ 3! = 65534)’ / etc / group> /etc/accountbackup/group.olds

Now copy the shadow file:

#Awk -v LIMIT = $ UGIDLIMIT -F: ‘($ 3> = LIMIT) && ($ 3! = 65534) {print $ 1}’ / etc / passwd | tee- | egrep -f- / etc / shadow> /root/accountbackup/shadow.old

Now, back up the user home directory and user mail:

#Tar -zcvpf /root/accountbackup/home.tar.gz/home

Now, back up user mail:

#Tar -zcvpf /root/move/mail.tar.gz / var / spool / mail

Now you have obtained the files related to the user account. Copy all data to the pen drive or new server via scp command. Before starting to migrate to the new server, make sure to back up all user-related files on the new server.

Restore the data to the new server.

## cat passwd.old >> / etc / passwd ## cat group.old >> / etc / group ## cat shadow.old >> / etc / shadow ## / bin / cp gshadow.old / etc / gshadow

Similarly, restore user data and user mail to the new server.

#Tar -zxvf /path/to/location/home.tar.gz#tar -zxvf /path/to/location/mail.tar.gz

In this article, we learned how to migrate user accounts from a Linux machine to another machine. Hope this helps you understand the files related to the user account and everything that needs to be moved.