OpenWrt Forum Archive

Topic: Change password remotely

The content of this topic has been archived on 20 Apr 2018. There are no obvious gaps in this topic, but there may still be some posts missing at the end.

How do I change password remotely using ssh?
I tried 'plink ... "echo -e 'adf\nadf' | passwd". But it doesn't work. However such command doesn't work in normal terminal. Is there any suitable batch command?

The problem solved using "expect" command.

I don't understand what you mean.

Do you have an example?

Duff wrote:

I don't understand what you mean.

Do you have an example?

I need to remotely run passwd command and automatically enter and retype password as a user could do manually. Or remotely change password somehow different way.

#passwd
...
Enter password: newpass
Re-type password: newppass
Password changed.

Yes, I understand.

But what command do you execute?

Duff wrote:

Yes, I understand.

But what command do you execute?

I downloaded "expect" program. This program can reply predefined phrases to expected queries using special script. To connect trhough SSH I use plink program - command line version of PuTTY.

The script:

#change_password host curpass newpass

set host [lindex $argv 0]
set curpass [lindex $argv 1]
set newpass [lindex $argv 2]

spawn plink $host

expect "login as:"
send "root\r"
expect "password:"
send "$curpass\r"

expect {
    "Access denied" "exit 1"
}

expect ":~#"
send "passwd\r"
expect "Enter new password:"
send "$newpass\r"
expect "Re-enter new password:"
send "$newpass\r"
expect ":~#"
send "exit\r"
exit 0

Ok, thanks.

Now, I have understand.

The discussion might have continued from here.