#!/usr/bin/perl use strict; use warnings; use Net::OpenSSH; use Expect; use Net::SSH::Expect; my $uName= "user"; my $ssh = Net::SSH::Expect->new ( host => "IPAddress", password=> "userPassword", user => $uName, raw_pty => 1 ); # logon to the SSH server using those credentials. my $login_output = $ssh->login(); if ($login_output !~ /Welcome/) { die "Login has failed. Login output was $login_output"; } #Random line display print "Connected to $uName\n"; #This is where I was trying the change password use case $ssh->send("passwd") or die "Cannot execute the passwd command: $!\n"; $ssh->waitfor("Changing password for user.\n (current) UNIX password: ", 3) or die "prompt 'password' not found after 1 second"; $ssh->send("oldPassword\n"); $ssh->waitfor("\n Enter new UNIX password: " , 2) or die "prompt 'New password:' not found"; $ssh->send("newPassword"); $ssh->waitfor("\n Retype new UNIX password: ", 1) or die "prompt 'Confirm new password:' not found"; $ssh->send("newPassword"); #$ssh->send("") or die "Cannot spawn: $!\n"; $ssh->close();