Guides and tutorials for Red Hat Linux, Debian, Suse and others.

Advertisement


DNS query tools & Network tools (Ping & Traceroute)

Linux change the password with output from echo command (standard input)

Postby debuser » Fri Jan 15, 2010 12:58 am

In Linux it is possible to change a user's password with the ouput of an echo command, coming from standard input, via pipe.
Code: Select all
NAME
       passwd - update a user’s authentication tokens(s)

SYNOPSIS
       passwd  [-k]  [-l] [-u [-f]] [-d] [-n mindays] [-x maxdays] [-w warndays] [-i inactivedays] [-S] [--stdin] [user-
       name]

DESCRIPTION
       Passwd is used to update a user’s authentication token(s).

       Passwd is configured to work through the Linux-PAM API.  Essentially, it initializes itself as a "passwd" service
       with Linux-PAM and utilizes configured password modules to authenticate and then update a user’s password.

       A simple entry in the Linux-PAM configuration file for this service would be:

        #
        # passwd service entry that does strength checking of
        # a proposed password before updating it.
        #
        passwd password requisite \
                    /usr/lib/security/pam_cracklib.so retry=3
        passwd password required \
                    /usr/lib/security/pam_unix.so use_authtok
        #

       Note, other module-types are not required for this application to function correctly.

OPTIONS
       -k     The  option,  -k,  is  used  to  indicate that the update should only be for expired authentication tokens
              (passwords); the user wishes to keep their non-expired tokens as before.

       -l     This option is used to lock the specified account and it is available to root only. The  locking  is  per-
              formed  by rendering the encrypted password into an invalid string (by prefixing the encrypted string with
              an !).

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


Example of reading password from standard input:
Code: Select all
# echo '123456789' | passwd --stdin tuser
Changing password for user tuser.
passwd: all authentication tokens updated successfully.

Above, user tuser's password was changed to '123456789'.
debuser
 
Posts: 70
Joined: Thu Aug 06, 2009 9:48 am


Advertisement


Return to Linux Distributions

Similar topics


Who is online

Users browsing this forum: No registered users and 0 guests