1

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::::::
7
  • Is this hard-coded? Or are the changes you want in a bash variable? Commented Oct 18, 2017 at 15:21
  • Why you should never edit /etc/shadow by hand Commented Oct 18, 2017 at 15:22
  • @Blacksilver its a hard coded
    – Med
    Commented Oct 18, 2017 at 15:30
  • @Zachary Brady i will put it on a script to change the password for the same user on many servers
    – Med
    Commented Oct 18, 2017 at 15:30
  • 2
    On Linux, you can use chpasswd -e to give it the already-encrypted password.
    – Jeff Schaller
    Commented Oct 18, 2017 at 15:50

2 Answers 2

5

instead:

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
1

Instead of the sed command you should do this:

usermod -p 'encrypted pw' user

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .