I need to achieve something very specific, and all the responses I find do not quite match my requirements. Therefore, if I am repeating a question I apologise.
I am trying to import many many users from one server to another. I can automate the user creation, but I need to copy over the passwords. To achieve this I'm planning to copy the hash from /etc/shadow on the old server to the same file on the new one.
I do not know the individual users' passwords from a plain text point of view, but I have confirmed that simply copying the hash over to the new shadow file maintains the password and the login works.
So what I'm trying to do is this :
I have a lookup list of usernames and hash's from the old server that looks like this :
So... two fields seperated by a space.
I have a destination shadow file which might look like this :
...since I've created all my new users without passwords at the moment.
And so, my solution would involve searching for each individual username in the destination shadow file, (username is specified by field 1 in my lookup list), and on that line replace the string "!!" with the correct password hash (hash specified by field 2 in my lookup list).
I can pull out the two fields from my lookup list by doing something like :
while read username passwordhash
echo "Username : " $username ", password : " $passwordhash
done < $SOURCEFILENAME
But I then need to use sed (or similar) to grep for one string, and on the resulting line replace another string with the new hash using the information from my lookup list for the search and replace strings, and without affecting the rest of the file.
I realise this is a very specific requirement, and there might be a better way to approach it altogether, but logically this seemed like a good solution. I'm just missing the scripting logic/commands.
Any suggestions on this would be awesome, since I'm not much of a bash guru, and it's driving me slightly insane
Many thanks in advance.