It is possible to manually generate and set encrypted password for a User ID in linux. You may also copy the encrypted password string from one Linux system’s /etc/shadow file and update the same on another system using chpasswd.
Manually generate encrypted password with openssl
[root@server1 ~]# echo 'mypassword' | openssl passwd -1 -stdin
$1$PCSqGwKq$rLcYcRDkg3jHPPs3N.gW6.
Update the hash for user ID
[root@server1 ~]# echo 'vijay:$1$PCSqGwKq$rLcYcRDkg3jHPPs3N.gW6.' | chpasswd -e
Now the user ‘vijay’ should be able to login with password ‘mypassword’.
Copy existing password from one server to another
Assuming that you have a second system in which you want the user to login with same password, you can create a user ID and set the same password. If the user has changed their password on the original system, we can copy the hash from /etc/shadow file in linux.
[root@server1 ~]# grep vijay /etc/shadow | awk -F':' '{ print $2 }'
$6$XVPzSMMx$epFAE7odRxcKnNRCqCZgdEQd4QO.V1bIA75GSyWUyH5q1nFX5ItnCro9Kb6DOIac9P8dylzGCgcrhcf8QjIvn0
Update the hash in secondary system
[root@server2 ~]# echo 'vijay:$6$XVPzSMMx$epFAE7odRxcKnNRCqCZgdEQd4QO.V1bIA75GSyWUyH5q1nFX5ItnCro9Kb6DOIac9P8dylzGCgcrhcf8QjIvn0' | chpasswd -e