Shadow

更改影子密碼

  • February 24, 2021

我正在尋找sed更改行的命令:

userA:$6$lhkjhl$sdlfhlmLMHQSDFM374FGSDFkjfh/7mD/354dshkKHQSkljhsd.sdmfjlk57HJ/:95170::::::

userA:$6$sLdkjf$576sdKUKJGKmlk565oiuljkljpi/9Fg/rst3587zet324etze.dsfgLIMLmdf/:34650::::::

反而:

chpasswd -e <<< 'userA:yourencryptedpassword'

如果您打算使用sed- 儘管存在風險:

設置密碼 - 無論之前是什麼:

sed -i.sedbackup 's/^\(userA:\)[^:]*\(:.*\)$/\1yournewpassword\2/' /etc/shadow

要替換特定的密碼字元串:

sed -i.sedbackup 's/^\(userA:\)youroldpassword\(:.*\)$/\1yournewpassword\2/' /etc/shadow

而不是sed命令,您應該這樣做:

usermod -p 'encrypted pw' user

引用自:https://unix.stackexchange.com/questions/398891