ssh and passwd scripting execution problems on linux

I'm having a problem here and I was wondering if anyone could help me? I'm putting together a password script. First off, I don't have root access. I have sudo access. Lets say the User ID is Trevor1, the password is H!rry23! and the server name is Linux1234

This is how the script begins

#!/bin/bash
 
 
read -p "Enter User ID"= useridname
read -p "Password"= userpasswd
 
read -p "Enter Server(s)"= servertext && echo $servertext > serverlist
 
for i in `cat serverlist`
do
echo "$i"
ssh $i sudo /usr/bin/passwd --stdin $useridname | echo -n $userpasswd
 
 
cat /dev/null > serverlist
done

Everything goes well until I get to this portion of the script :

ssh $i sudo /usr/bin/passwd --stdin $useridname | echo -n $userpasswd

The the output is:

Linux1234
H!rry23! Enter passphrase for key '/local_home/username/.ssh/id_dsa

After I enter the passphrase key and press enter, the cusor will just sit there forever.

After a long while i'll get this output:

passwd: Authentication information cannot be recovered

What's going wrong? And how can this be fixed

what do you want to do after you ssh?

I want the password echoed into the passwd command.

It's passwd, not echo, that should be reading from the pipe:

$ echo password | passwd --stdin ....

Not sure how that sits with your SUDO rule, though.

I changed the command to :

echo $userpasswd | /usr/bin/passwd --stdin $useridname

and I get this output:

Only root can do that.
Enter passphrase for key '/local_home/username/.ssh/id_dsa':

So, is it safe to assume that I'll need root access to the command passwd?

I have no idea where the 'passphrase for key' came from, usually ssh gives that.

Yes, of course you need to be root to change someone else's password :eek: