View Single Post

  #7 (permalink)  
Old 06-24-2008
Dave B
 
Posts: n/a
Default Re: How to set password from command line

Ignoramus19021 wrote:
> On 2008-06-24, Dave B <daveb@addr.invalid> wrote:
>> Ignoramus19021 wrote:
>>
>>>>> I am not interested in BS lectures about security.
>>> And I would prefer to deal with an excrypted password.

>> Uhm...reread the two phrases above. Anyway, why not edit /etc/shadow
>> directly then?
>>
>> awk -F':' -v OFS=':' '/^root/{$2=encryptedpassw}1' /etc/shadow > newshadow
>>

>
> I think that your answer will work. I was hoping that there is a tool
> "guaranteed" to work and a member of the passwd family, but worst case
> is, I can do it with a script as you said.
>
> Your command does not seem to work actually:
>
> $$$ awk -F':' -v OFS=':' '/^root/{$2=encryptedpassw}1' /etc/shadow |grep root
> root::13944:0:99999:7:::


Of course, you have to supply the actual encrypted password, either directly, eg

awk -F':' -v OFS=':' '/^root/{$2="%@/&-:()"}1' /etc/shadow |grep root

or with a variable, eg

awk -F':' -v OFS=':' -v pw='%@/&-:()' '/^root/{$2=pw}1' /etc/shadow

Replace the "%@/&-:()" string with the actual encrypted password.

--
D.
Reply With Quote