To move or migrate user accounts from an old Linux server to a new Linux server, you can use the following steps:
awk
command to extract the username and home directory fields from the /etc/passwd
file, like this:awk -F: '{print $1 " " }' /etc/passwd
This will print a list of user accounts with the username and home directory separated by a space. You can save this list to a file for later reference.
useradd
command to create a new user account, like this:useradd -d /home/username -m username
This will create a new user account with the specified username and home directory, and create the home directory if it does not already exist.
tar
command to create a tar archive, like this:tar -czf username.tar.gz /home/username
This will create a tar archive named username.tar.gz
of the /home/username
directory.
Transfer the tar archives to the new server using a secure file transfer method, such as scp
or rsync
.
On the new server, extract the tar archives to the corresponding user's home directories. You can use the tar
command to extract the tar archives, like this:
tar -xzf username.tar.gz -C /home/username
This will extract the contents of the username.tar.gz
archive to the /home/username
directory on the new server.
chown
and chmod
commands to set the ownership and permissions, like this:chown -R username: /home/username chmod -R 700 /home/username
This will set the ownership of all files and directories in the /home/username
directory to the username
user and group, and set the permissions to 700
(read, write, and execute for the owner, and no access for others).