sub ssh_login { my ( $remote_server, $username, $password ) = @_; my $ssh = Net::SSH::Expect->new( host => $remote_server, password => $password, user => $username, raw_pty => 0, #no_terminal => 1, #port => $port, timeout=>10, #terminator=>"\r\n", log_file => '/tmp/test_ssh.log', exp_debug =>1, exp_internal =>1, ); # 2) logon to the SSH server using those credentials. # test the login output to make sure we had success my $login_output = $ssh->login(); if ( $login_output !~ /.*/ ) { #$logger->error("$0:Login has failed. Login output was $login_output"); print "$0:Login has failed. Login output was $login_output" . "\n"; } $ssh->exec("stty raw -echo"); return $ssh; }