Chinaunix首页 | 论坛 | 博客
  • 博客访问: 3016385
  • 博文数量: 535
  • 博客积分: 15788
  • 博客等级: 上将
  • 技术积分: 6507
  • 用 户 组: 普通用户
  • 注册时间: 2007-03-07 09:11
文章分类

全部博文(535)

文章存档

2016年(1)

2015年(1)

2014年(10)

2013年(26)

2012年(43)

2011年(86)

2010年(76)

2009年(136)

2008年(97)

2007年(59)

分类:

2009-08-28 10:20:49

For a perl implementation that does not require the system ssh command, see Net::SSH::Perl instead.

For a wrapper version that allows you to use passwords, see Net::SSH::Expect instead.

For another non-forking version that uses the libssh2 library, see Net::SSH2.

For a way to execute remote Perl code over an ssh connection see IPC::PerlSSH.


1、
wget

[root@srv14 Net-SSH2-0.24]# perl Makefile.PL 

The libssh2 library is required by this module.  If you don't have it, you can
download it from you may also need OpenSSL, which can be
obtained from

On Debian do:
sudo aptitude install libssh2-1-dev

Can't link/include 'libssh2.h', 'ssh2'


2、
wget
./configure --prefix=/usr/local/libssh2
make
make install

 
ExtUtils-MakeMaker

3、修改Net-SSH2的makefile.pl文件,添加刚才的libssh2的安装目录(如果安装时不指定目录则不需要)
vi Makefile.PL

my @search_paths = (
  $Config{siteprefixexp}, $Config{prefixexp},
  '/usr', '/usr/local', '/opt','/usr/local/libssh2',
  $ENV{HOME}
);

4、[root@srv12 Net-SSH2-0.24]# perl Makefile.PL 

The libssh2 library is required by this module.  If you don't have it, you can
download it from you may also need OpenSSL, which can be
obtained from

On Debian do:
sudo aptitude install libssh2-1-dev

Checking if your kit is complete...
Looks good
Warning: prerequisite ExtUtils::MakeMaker 6.42 not found. We have 6.30.
Writing Makefile for Net::SSH2

ExtUtils::MakeMaker版本低,升级一下吧:
wget

[root@srv12 ExtUtils-MakeMaker-6.54]# perl Makefile.PL 
Checking if your kit is complete...
Looks good
Using included version of ExtUtils::Manifest (1.56) as it is newer than the installed version (1.46).
Using included version of ExtUtils::Command (1.16) as it is newer than the installed version (1.09).
Using included version of ExtUtils::Installed (1.43) as it is newer than the installed version (0.08).
Using included version of ExtUtils::Packlist (1.43) as it is newer than the installed version (0.04).
Using included version of ExtUtils::Install (1.52) as it is newer than the installed version (1.33).
Writing Makefile for ExtUtils::MakeMaker

make 
make install

OK,安装Net::SSH2
[root@srv12 Net-SSH2-0.24]# perl Makefile.PL 

The libssh2 library is required by this module.  If you don't have it, you can
download it from you may also need OpenSSL, which can be
obtained from

On Debian do:
sudo aptitude install libssh2-1-dev

Writing Makefile for Net::SSH2
其实似乎不升级ExtUtils::MakeMaker也可以,因为不升级也可以生成Makefile文件。

关于上面的提示:仅仅是提示而已,不管你是不是装了libssh,openssl,它都会提示,看一下makefile.pl就知道了。

现在可以make,make install了。

另外,如果在make时:
           -L/usr/local/lib -L/usr/lib -lssh2 -lz -lssl -lcrypto        \
          
/usr/bin/ld: cannot find -lssl
collect2: ld returned 1 exit status
make: *** [blib/arch/auto/Net/SSH2/SSH2.so] Error 1

需要安装openssl-devel包。


安装完成,测试
#!/usr/bin/perl -w
use Net::SSH2;

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

$ssh2->connect('118.219.3.105') or die $!;

         if ($ssh2->auth_password('root','test@test.com')) {
             my $chan = $ssh2->channel();
             $chan->exec('date >/tmp/123');
}
注:exec的输出不在perl脚本的执行端
阅读(4268) | 评论(0) | 转发(1) |
给主人留下些什么吧!~~