Member-only story
Migrate SSH users from one server to another
In this post, we’ll see how we can migrate SSH users from one server to another server. We’ll cover following scenarios:
ec2-user: exists on both the servers
new_user: ssh key for the user not available on server1
new_user2: /home directory exists but /home/.ssh directory doesn’t exist(on server2)
new_user3: /home and /home/.ssh directory exist but /home/.ssh/authorized_keys file is not there(n server2)
new_user4: user doesn’t exist on server1
Pre-requisite: 2 servers with password authentication enabled. On server 2 we need a user that can ssh into server1. We also need sshpass package installed on server2.
Step 1: Let’s have a look at what files and directories we have on server 1.
Step 2: On server2, create a file named user.txt with the list of user names we need to create on this server.
cat user.txtec2-user
new_user
new_user2
new_user3
new_user4
Step 3: On server2, create a file named password.txt with the password we need in order to ssh into server1
cat password.txtNewtestPassword2020#