#!perl use 5.012; # strict, // use warnings; use autodie; my $hostname = "obfuscated"; my $username = "obfuscated"; my $known_hosts = '/obfuscated/.ssh/known_hosts'; my ($id_rsa, $id_ecdsa, $id_ed25519) = map '/obfuscated/.ssh/'.$_, qw/id_rsa id_ecdsa id_ed25519/; use Net::SSH::Perl; use Data::Dump; my %options = ( # debug => 1, # set this one to help with debug protocol => 2, # ssh2 interactive => 1, # ask for password if something goes wrong strict_host_key_checking => 'yes', # makes sure it actually checks known hosts options => [ "UserKnownHostsFile $known_hosts", # defines the user path/name for known_hosts ], identity_files => [$id_rsa, $id_ed25519, $id_ecdsa], # defines the possible identity_file path strings ); my $ssh = Net::SSH::Perl::->new($hostname, %options) or die "create ssh: $!"; #dd $ssh; # use this when debugging the various %options $ssh->login($username) or die "login: $!"; # using id_rsa identification, at default id_rsa location, or ask for pw if it fails print map { $_//"\n", "\n----\n"} $ssh->cmd('pwd');