How to set password from command line

This is a discussion on How to set password from command line within the Linux General forums, part of the Linux Forums category; On 2008-06-24, Ignoramus19021 wrote: > I want a NON-INTERACTIVE command to set root password. > > Similar ...


Go Back   Usenet Forums > Linux Forums > Linux General

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 06-24-2008
Chris F.A. Johnson
 
Posts: n/a
Default Re: How to set password from command line

On 2008-06-24, Ignoramus19021 wrote:
> I want a NON-INTERACTIVE command to set root password.
>
> Similar to how I can set a samba password by supplying an encrypted
> password on command line, or a password for the user in a self install
> CD.
>
> I am not interested in BS lectures about security.
>
> This is for a large number of GUI-less production machines that we'll
> be setting up, not for grandma's web browser box. The machines are all
> fully configured with a big install script, except that I need to set
> root password manually, which I do not like to do.
>
> So. Is there some way to set
>
> set-encrypted-password root <encrypted password>


man passwd:

--stdin
This option is used to indicate that passwd should read
the new password from standard input, which can be a
pipe.


--
Chris F.A. Johnson, author | <http://cfaj.freeshell.org>
Shell Scripting Recipes: | My code in this post, if any,
A Problem-Solution Approach | is released under the
2005, Apress | GNU General Public Licence
Reply With Quote
  #2 (permalink)  
Old 06-24-2008
Ignoramus19021
 
Posts: n/a
Default How to set password from command line

I want a NON-INTERACTIVE command to set root password.

Similar to how I can set a samba password by supplying an encrypted
password on command line, or a password for the user in a self install
CD.

I am not interested in BS lectures about security.

This is for a large number of GUI-less production machines that we'll
be setting up, not for grandma's web browser box. The machines are all
fully configured with a big install script, except that I need to set
root password manually, which I do not like to do.

So. Is there some way to set

set-encrypted-password root <encrypted password>

thanks

--
Due to extreme spam originating from Google Groups, and their inattention
to spammers, I and many others block all articles originating
from Google Groups. If you want your postings to be seen by
more readers you will need to find a different means of
posting on Usenet.
http://improve-usenet.org/
Reply With Quote
  #3 (permalink)  
Old 06-24-2008
Ignoramus19021
 
Posts: n/a
Default Re: How to set password from command line

On 2008-06-24, Chris F.A. Johnson <cfajohnson@gmail.com> wrote:
> On 2008-06-24, Ignoramus19021 wrote:
>> I want a NON-INTERACTIVE command to set root password.
>>
>> Similar to how I can set a samba password by supplying an encrypted
>> password on command line, or a password for the user in a self install
>> CD.
>>
>> I am not interested in BS lectures about security.
>>
>> This is for a large number of GUI-less production machines that we'll
>> be setting up, not for grandma's web browser box. The machines are all
>> fully configured with a big install script, except that I need to set
>> root password manually, which I do not like to do.
>>
>> So. Is there some way to set
>>
>> set-encrypted-password root <encrypted password>

>
> man passwd:
>
> This option is used to indicate that passwd should read
> the new password from standard input, which can be a
> pipe.
>
>


I think that your passwd is different from my passwd, mine does not
have this option. And I would prefer to deal with an excrypted
password.
--
Due to extreme spam originating from Google Groups, and their inattention
to spammers, I and many others block all articles originating
from Google Groups. If you want your postings to be seen by
more readers you will need to find a different means of
posting on Usenet.
http://improve-usenet.org/
Reply With Quote
  #4 (permalink)  
Old 06-24-2008
Dave B
 
Posts: n/a
Default Re: How to set password from command line

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

--
D.
Reply With Quote
  #5 (permalink)  
Old 06-24-2008
Dave B
 
Posts: n/a
Default Re: How to set password from command line

Dave B 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


With sed you can even do in-place editing (carefully):

sed -i 's/^root:[^:]*/root:encryptedpassword/' /etc/shadow

--
D.
Reply With Quote
  #6 (permalink)  
Old 06-24-2008
Ignoramus19021
 
Posts: n/a
Default Re: How to set password from command line

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:::

I thought that the password field would get set to encryptedpassw?

--
Due to extreme spam originating from Google Groups, and their inattention
to spammers, I and many others block all articles originating
from Google Groups. If you want your postings to be seen by
more readers you will need to find a different means of
posting on Usenet.
http://improve-usenet.org/
Reply With Quote
  #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
  #8 (permalink)  
Old 06-24-2008
Robert Heller
 
Posts: n/a
Default Re: How to set password from command line

At Tue, 24 Jun 2008 11:09:50 -0500 Ignoramus19021 <ignoramus19021@NOSPAM.19021.invalid> wrote:

>
> On 2008-06-24, Chris F.A. Johnson <cfajohnson@gmail.com> wrote:
> > On 2008-06-24, Ignoramus19021 wrote:
> >> I want a NON-INTERACTIVE command to set root password.
> >>
> >> Similar to how I can set a samba password by supplying an encrypted
> >> password on command line, or a password for the user in a self install
> >> CD.
> >>
> >> I am not interested in BS lectures about security.
> >>
> >> This is for a large number of GUI-less production machines that we'll
> >> be setting up, not for grandma's web browser box. The machines are all
> >> fully configured with a big install script, except that I need to set
> >> root password manually, which I do not like to do.
> >>
> >> So. Is there some way to set
> >>
> >> set-encrypted-password root <encrypted password>

> >
> > man passwd:
> >
> > This option is used to indicate that passwd should read
> > the new password from standard input, which can be a
> > pipe.
> >
> >

>
> I think that your passwd is different from my passwd, mine does not
> have this option. And I would prefer to deal with an excrypted
> password.


If you already have a properly encrypted password:

# assumes that the shell variable encryptedpassword contains the
# properly encrypted password
# Use sed to directly edit the passwd file (it is after all just a *plain
# text file*).
sed "s/^root:[^:]*:/root:$encryptedpassword:/g" </etc/passwd >/etc/passwd.new
# Paranoid backups of /etc/passwd (trashing this file can be bad news!)
cp -f /etc/passwd /etc/passwd.old
mv -f /etc/passwd.new /etc/passwd
# Update /etc/shadow file
pwck -r
pwconv

(If everything is sane, you can remove /etc/passwd.old at your leisure.)

If you are using RHEL/CentOS (or FC), I believe the kickstart shell can
do this OR the above can be incorporated into the kickstart process.

--
Robert Heller -- Get the Deepwoods Software FireFox Toolbar!
Deepwoods Software -- Linux Installation and Administration
http://www.deepsoft.com/ -- Web Hosting, with CGI and Database
heller@deepsoft.com -- Contract Programming: C/C++, Tcl/Tk

Reply With Quote
  #9 (permalink)  
Old 06-24-2008
Ignoramus19021
 
Posts: n/a
Default Re: How to set password from command line

On 2008-06-24, Robert Heller <heller@deepsoft.com> wrote:
> At Tue, 24 Jun 2008 11:09:50 -0500 Ignoramus19021 <ignoramus19021@NOSPAM.19021.invalid> wrote:
>
>>
>> On 2008-06-24, Chris F.A. Johnson <cfajohnson@gmail.com> wrote:
>> > On 2008-06-24, Ignoramus19021 wrote:
>> >> I want a NON-INTERACTIVE command to set root password.
>> >>
>> >> Similar to how I can set a samba password by supplying an encrypted
>> >> password on command line, or a password for the user in a self install
>> >> CD.
>> >>
>> >> I am not interested in BS lectures about security.
>> >>
>> >> This is for a large number of GUI-less production machines that we'll
>> >> be setting up, not for grandma's web browser box. The machines are all
>> >> fully configured with a big install script, except that I need to set
>> >> root password manually, which I do not like to do.
>> >>
>> >> So. Is there some way to set
>> >>
>> >> set-encrypted-password root <encrypted password>
>> >
>> > man passwd:
>> >
>> > This option is used to indicate that passwd should read
>> > the new password from standard input, which can be a
>> > pipe.
>> >
>> >

>>
>> I think that your passwd is different from my passwd, mine does not
>> have this option. And I would prefer to deal with an excrypted
>> password.

>
> If you already have a properly encrypted password:
>
> # assumes that the shell variable encryptedpassword contains the
> # properly encrypted password
> # Use sed to directly edit the passwd file (it is after all just a *plain
> # text file*).
> sed "s/^root:[^:]*:/root:$encryptedpassword:/g" </etc/passwd >/etc/passwd.new
> # Paranoid backups of /etc/passwd (trashing this file can be bad news!)
> cp -f /etc/passwd /etc/passwd.old
> mv -f /etc/passwd.new /etc/passwd
> # Update /etc/shadow file
> pwck -r
> pwconv
>
> (If everything is sane, you can remove /etc/passwd.old at your leisure.)
>
> If you are using RHEL/CentOS (or FC), I believe the kickstart shell can
> do this OR the above can be incorporated into the kickstart process.
>


I am using ubuntu Gutsy and I made a custom kickstart disk.

The self install script that I am talking about, runs from the
kickstart process.

I think that I will do something along the above lines.
--
Due to extreme spam originating from Google Groups, and their inattention
to spammers, I and many others block all articles originating
from Google Groups. If you want your postings to be seen by
more readers you will need to find a different means of
posting on Usenet.
http://improve-usenet.org/
Reply With Quote
  #10 (permalink)  
Old 06-24-2008
Ignoramus19021
 
Posts: n/a
Default Re: How to set password from command line

On 2008-06-24, Dave B <daveb@addr.invalid> wrote:
> 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.
>


this one works great, thanks a lot
--
Due to extreme spam originating from Google Groups, and their inattention
to spammers, I and many others block all articles originating
from Google Groups. If you want your postings to be seen by
more readers you will need to find a different means of
posting on Usenet.
http://improve-usenet.org/
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 04:37 PM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0