#!/usr/bin/perl use strict; use warnings; use Net::SSH::Perl; my $user = 'user'; my $pass = 'password'; my $cmd = "ls /root"; my $ssh = Net::SSH::Perl->new('localhost', debug => 1, protocol => 2, use_pty => 1, ); $ssh->login($user, $pass) ; if ($cmd) { my($stdout, $stderr, $exit) = $ssh->cmd($cmd); print $stdout if $stdout; print $stderr if $stderr; } else { eval "use Term::ReadKey;"; ReadMode('raw'); eval "END { ReadMode('restore') };"; $ssh->shell; print "Connection to host closed.\n"; } __END__