Try chpasswd . Unlike passwd , you can pass the username and password to standard command input. Thus, you can, for example, upload a file containing a password and put this line in your file:
sudo('chpasswd < my_password_file')
From man chpasswd :
The chpasswd command reads a list of username and password pairs from standard input and uses this information to update a group of existing users. Each line has the format:
user_name: password
The passwords provided must be in text form.
source share