如何在远程设备上通过SSH运行命令?

时间:2018-01-27 12:39:16

标签: linux perl ssh remote-access remote-execution

如何在远程设备上通过SSH运行命令?

我正在尝试下一个想法:

1:

[root@0400smarts-voip01 test]# ssh user@IP "my command"
user@IP's password:
Connection to IP closed by remote host.

2:

[root@0400smarts-voip01 test]# ssh -t user@IP "my command"
user@IP's password:
Connection to IP closed by remote host.
Connection to IP closed.

此外,我正在尝试通过Perl脚本运行命令:

#!/bin/perl
use strict;

use Net::OpenSSH;

my $hostname = "IP";
my $username = "user";
my $password = "password";
my $cmd = "command";

my $ssh = Net::OpenSSH->new(host=>"$hostname", user=>"$username", port=>22, password=>"$password");
$ssh->system($cmd);

但是这种方法也行不通:

[root@0400smarts-voip01 test]# ./test.pl
Connection to IP closed by remote host.

我该如何解决这个问题?

0 个答案:

没有答案