I am looking for a sed
command to change the line:
userA:$6$lhkjhl$sdlfhlmLMHQSDFM374FGSDFkjfh/7mD/354dshkKHQSkljhsd.sdmfjlk57HJ/:95170::::::
to
userA:$6$sLdkjf$576sdKUKJGKmlk565oiuljkljpi/9Fg/rst3587zet324etze.dsfgLIMLmdf/:34650::::::
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.
Sign up to join this communityinstead:
chpasswd -e <<< 'userA:yourencryptedpassword'
If you were going to use sed
- despite the risks:
To set a password - no matter what it was before:
sed -i.sedbackup 's/^\(userA:\)[^:]*\(:.*\)$/\1yournewpassword\2/' /etc/shadow
To replace a specific password string:
sed -i.sedbackup 's/^\(userA:\)youroldpassword\(:.*\)$/\1yournewpassword\2/' /etc/shadow
chpasswd -e
to give it the already-encrypted password.