How to set password from command line - Ubuntu

This is a discussion on How to set password from command line - Ubuntu ; 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 ...

+ Reply to Thread
Results 1 to 14 of 14

Thread: How to set password from command line

  1. 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


    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 |
    Shell Scripting Recipes: | My code in this post, if any,
    A Problem-Solution Approach | is released under the
    2005, Apress | GNU General Public Licence

  2. 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

    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/

  3. Re: How to set password from command line

    On 2008-06-24, Chris F.A. Johnson 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

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

  4. 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.

  5. 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.

  6. Re: How to set password from command line

    On 2008-06-24, 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
    >


    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/

  7. Re: How to set password from command line

    Ignoramus19021 wrote:
    > On 2008-06-24, 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
    >>

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

  8. Re: How to set password from command line

    At Tue, 24 Jun 2008 11:09:50 -0500 Ignoramus19021 wrote:

    >
    > On 2008-06-24, Chris F.A. Johnson 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

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


  9. Re: How to set password from command line

    On 2008-06-24, Robert Heller wrote:
    > At Tue, 24 Jun 2008 11:09:50 -0500 Ignoramus19021 wrote:
    >
    >>
    >> On 2008-06-24, Chris F.A. Johnson 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
    >> >
    >> > 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.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/

  10. Re: How to set password from command line

    On 2008-06-24, Dave B wrote:
    > Ignoramus19021 wrote:
    >> On 2008-06-24, 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
    >>>

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

  11. Re: How to set password from command line

    Ignoramus19021 illuminated alt.os.linux.ubuntu by typing:

    >
    > I am not interested in BS lectures about security.


    Oh. Hello.

    Here's another dig at Ubuntu's security policy. You seem to be making
    a habit out of it.

    If you recall, you were taken to task for instructing a new Ubuntu
    user to enable his root account and password in alt.os.linux.ubuntu.

    You were wrong to do that.

    And anyway, if you don't like Ubuntu's default security policy, change
    the bloody thing or use a different distro for crying out loud.

    Stop bleating.

    --
    Moog

    “Are you going to come quietly, or do I have to use earplugs?”

  12. Re: How to set password from command line

    unhelpful answer

    On 2008-06-24, Moog wrote:
    > Ignoramus19021 illuminated alt.os.linux.ubuntu by typing:
    >
    >>
    >> I am not interested in BS lectures about security.

    >
    > Oh. Hello.
    >
    > Here's another dig at Ubuntu's security policy. You seem to be making
    > a habit out of it.
    >
    > If you recall, you were taken to task for instructing a new Ubuntu
    > user to enable his root account and password in alt.os.linux.ubuntu.
    >
    > You were wrong to do that.
    >
    > And anyway, if you don't like Ubuntu's default security policy, change
    > the bloody thing or use a different distro for crying out loud.
    >
    > Stop bleating.
    >


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

  13. Re: How to set password from command line

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

    usermod -p 'PASSWORD' root

    USERMOD(8) System Management Commands USERMOD(8)

    NAME
    usermod - modify a user account

    SYNOPSIS
    usermod [options] LOGIN

    DESCRIPTION
    The usermod command modifies the system account files to reflect the
    changes that are specified on the command line.

    OPTIONS
    -p, --password PASSWORD
    The encrypted password, as returned by crypt(3).


    R'

  14. Re: How to set password from command line

    On 2008-06-25, Ralf Fassel wrote:
    > * Ignoramus19021
    >| I want a NON-INTERACTIVE command to set root password.
    >
    > usermod -p 'PASSWORD' root


    Perfect, exactly what I was looking for, and yes, my ststem has it. I
    am very happy. Thanks a lot

    i

    > USERMOD(8) System Management Commands USERMOD(8)
    >
    > NAME
    > usermod - modify a user account
    >
    > SYNOPSIS
    > usermod [options] LOGIN
    >
    > DESCRIPTION
    > The usermod command modifies the system account files to reflect the
    > changes that are specified on the command line.
    >
    > OPTIONS
    > -p, --password PASSWORD
    > The encrypted password, as returned by crypt(3).
    >
    >
    > R'


    --
    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 to Thread