use strict; use warnings; use Net::SSH::Perl; my($host, $username, $new_password, $old_password); $host = "IPADRESSE"; $username = "USERNAME"; $old_password = "PASSWORD"; my $ssh = Net::SSH::Perl->new($host, debug => 1, protocol => 2); $ssh->login($username, $old_password); $ssh->register_handler("stderr", sub { my($channel, $buffer) = @_; my $str = $buffer->bytes; if ($str eq "(current) UNIX password: ") { $channel->send_data($old_password); } elsif ($str eq "New UNIX password: ") { $channel->send_data($new_password); } elsif ($str eq "Retype new UNIX password: ") { $channel->send_data($new_password); } }); $ssh->cmd('passwd');