Results 1 to 4 of 4

Thread: Changing user passwords

  1. #1
    Join Date
    Sep 2008
    Location
    Texas
    Beans
    4
    Distro
    Ubuntu 9.04 Jaunty Jackalope

    Changing user passwords

    In a nutshell
    I am trying to change a list of users passwords with a bash script. This link (http://www.howtoforge.com/user_passw..._a_bash_script) was helpful but the password part doesn't work for me.
    Is there a way to change a users password with just a single line. Or is there a way to send text back to the screen when it asks you to enter your new password?

    Password Script
    #!/bin/sh
    for i in `more userlist.txt `
    do
    echo $i
    echo $i"123" | passwd –-stdin "$i"
    done

    Ubuntu Server 8.04

  2. #2
    Join Date
    Jan 2007
    Location
    Ottawa, Canada
    Beans
    302

    Re: Changing user passwords

    Code:
    #!/bin/bash
    # 1st param - pswd
    # 2nd param - text-file with usernames, one per line
    
    if [ $# -lt 2 ]; then
    	echo "Usage: ./passwd.sh <passwd> <text file>"
    	exit
    fi
    
    for i in `cat $2`; do
    	echo "$i:$1"
    	yes "$1" | passwd "$i"
    done
    here you go

    if you want, i can modify it to read a txt file that has both username and passwd on each line and then set the passwd accordingly

  3. #3
    Join Date
    Sep 2008
    Location
    Texas
    Beans
    4
    Distro
    Ubuntu 9.04 Jaunty Jackalope

    Talking Re: Changing user passwords

    THANKS!
    I will give that shot. I will just add the password expire line to the bottom and that should give all the new users I create a temp pass and then make them change it at first login. I will let you know my results.
    Thanks Again!!

  4. #4
    Join Date
    Sep 2008
    Location
    Texas
    Beans
    4
    Distro
    Ubuntu 9.04 Jaunty Jackalope

    Talking Re: Changing user passwords

    Quote Originally Posted by supersonicdarky View Post
    Code:
    #!/bin/bash
    # 1st param - pswd
    # 2nd param - text-file with usernames, one per line
    
    if [ $# -lt 2 ]; then
    	echo "Usage: ./passwd.sh <passwd> <text file>"
    	exit
    fi
    
    for i in `cat $2`; do
    	echo "$i:$1"
    	yes "$1" | passwd "$i"
    done
    here you go

    if you want, i can modify it to read a txt file that has both username and passwd on each line and then set the passwd accordingly
    I tried your code a couple of different ways and kept getting a line 14 syntax error which I couldn't figure out. However you did get me on the right track. I did some digging on alternative ways to change and re-wrote it like so
    Code:
    #!/bin/sh
    for i in `more userlist.txt `
    do
    echo $i
    echo $i:temp123 | chpasswd
    passwd $i -e
    echo; echo "User $i will be forced to change password on next login!"
    done
    Worked out like a champ!!
    Thanks for your all your help.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •