简体   繁体   中英

$ssh2-> connect('host') how can I find what host should be?

I'm trying to connect to my work linux box with perl SSH2 using this code I found off the internet. When I run it it returns unable to connect to host. Can somebody tell me how to find the host to put into the ssh2 -> connect. I assume myusername-lnx is correct because that is what I get when I run >hostname on my linux box. Should I be using the output form >hostname or something else. If the output from hostname is the correct thing to be using any other suggestions on what I might be doing wrong that would cause the ssh2->connect not to work.

#!/usr/bin/perl
use warnings;
use strict;
use Net::SSH2;

my $ssh2 = Net::SSH2->new();

$ssh2->connect('myusername-lnx') or die "Unable to connect Host \n";
$ssh2->auth_password('my_username','my_password') or die "Unable to login \n";

According to the documentation for Net::SSH2 , connect does take a hostname. You can get a better error message like so:

$ssh2->connect('myusername-lnx') or $ssh2->die_with_error;

I'm trying to connect to my work linux box...

Try a normal ssh myusername-lnx . If that doesn't work then Net::SSH2 isn't going to work either.

If you're not at work, it's likely your local machine doesn't know what host myusername-lnx is. hostname returns what the machine calls itself, but that isn't necessarily what anything else knows it as. The hostname probably needs to be fully qualified, that is it needs the domain part like myusername-lnx.somehost.com . It's kind of like asking for "Janice". There might be only one "Janice" at work, but outside of work there's lots of Janices, so you'll have to be more specific.

It's even possible (in fact, probable) your work machine cannot be contacted from outside the work network. You might need to use a VPN to get into the network.

You'll need to figure out what hostname or IP address to use. Unfortunately we can't tell you that. You should ask your network administrator at work how you access a work machine outside of work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM