I am looking for a sed command to change the line:



  • Is this hard-coded? Or are the changes you want in a bash variable? – SIGSTACKFAULT Oct 18 '17 at 15:21
  • @Blacksilver its a hard coded – Med Oct 18 '17 at 15:30
  • @Zachary Brady i will put it on a script to change the password for the same user on many servers – Med Oct 18 '17 at 15:30
  • 2
    On Linux, you can use chpasswd -e to give it the already-encrypted password. – Jeff Schaller Oct 18 '17 at 15:50


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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.