perl 离线安装 Net::OpenSSH 库

Net::OpenSSH 库 下载地址
https://metacpan.org/pod/Net::OpenSSH
直接获取安装包命令

wget https://cpan.metacpan.org/authors/id/S/SA/SALVA/Net-OpenSSH-0.74.tar.gz

编译方式

perl Makefile.PL
make && make install

Net::OpenSSH 库 还需要用到IO:Pty 库,所以我们还需要继续安装 IO:Pty 库

IO:Pty 库 下载地址
https://metacpan.org/pod/IO::Pty
直接获取安装包命令

wget  https://cpan.metacpan.org/authors/id/T/TO/TODDR/IO-Tty-1.12.tar.gz

编译方式

perl Makefile.PL
make && make install

测试test.pl 程序

use Net::OpenSSH;
use strict;
use Encode;
use POSIX qw(strftime); my $host="192.168.57.129";
my $user_name="root";
my $password="chen"; my $ssh = Net::OpenSSH->new($host,user => $user_name,password => $password);
my @ls = $ssh->capture("ls /");
$ssh->error and die "remote ls command failed: " . $ssh->error;
print "test:\n".@ls."\n";
foreach my $item (@ls) {
print "-------".$item."\n";
}
print "========================\n";

运行方法

perl test.pl

这里给大家提一个醒,由于Net::OpenSSH 的库在连接远程服务器时,客户端机器的IP 地址必须要要在 被访问服务器的 ~/.ssh/known_hosts 文件下,否则会报告错误。

错误的信息如下:

remote ls command failed: unable to establish master SSH connection: the authenticity of the target host can't be established; the remote host public key is probably not present on the '~/.ssh/known_hosts' file at test.pl line 13.

详细的解释可以参考官方说明,https://metacpan.org/pod/Net::OpenSSH

Check you can connect to the remote host using the same parameters you are passing to Net::OpenSSH. In particular, ensure that you are running ssh as the same local user.

If you are running your script from a web server, the user would probably be www, apache or something alike.

Common problems are:

Remote host public key not present in known_hosts file.

The SSH protocol uses public keys to identify the remote hosts so that they can not be supplanted by some malicious third parties.

For OpenSSH, usually the server public key is stored in /etc/ssh/ssh_host_dsa_key.pub or in /etc/ssh/ssh_host_rsa_key.pub and that key should be copied into the ~/.ssh/known_hosts file in the local machine (other SSH implementations may use other file locations).

Maintaining the server keys when several hosts and clients are involved may be somewhat inconvenient, so most SSH clients, by default, when a new connection is established to a host whose key is not in the known_hosts file, show the key and ask the user if he wants the key copied there.

Wrong remote host public key in known_hosts file.

This is another common problem that happens when some server is replaced or reinstalled from scratch and its public key changes becoming different to that installed on the known_hosts file.

The easiest way to solve that problem is to remove the old key from the known_hosts file by hand using any editor and then to connect to the server replying yes when asked to save the new key.

Wrong permissions for the ~/.ssh directory or its contents.

OpenSSH client performs several checks on the access permissions of the ~/.ssh directory and its contents and refuses to use them when misconfigured. See the FILES section from the ssh() man page.

Incorrect settings for password or public key authentication.

Check that you are using the right password or that the user public key is correctly installed on the server.

安装Net::OpenSSH 库的更多相关文章

  1. 安装Python算法库

    安装Python算法库 主要包括用NumPy和SciPy来处理数据,用Matplotlib来实现数据可视化.为了适应处理大规模数据的需求,python在此基础上开发了Scikit-Learn机器学习算 ...

  2. kali4.0 安装32位库

    一.前情提要: OS:Kali4.0 64bit 二.安装32位库: 错误方法:sudo apt-get install lib6-i386 正确方法如下: 1.先以root用户身份登陆: su ro ...

  3. ubuntu 下安装32位库 ia32-libs方法

    这两天在整Linux系统,要配置JDK,SDK环境,但是SDK配置使用的时候,提示没有权限. 需要安装32位库来解决,还有就是在修改文件的时候提示不能修改.唉...反正就是没有办法正常操作啦 后来根据 ...

  4. phpstudy 出现“请自行检查是否安装VC9运行库??”问题 -- 缺少vc9库

    phpStudy是一款PHP调试环境的程序集成包,该程序包集成最新的Apache+PHP+MySQL+phpMyAdmin+ZendOptimizer,一次性安装,无须配置即可使用,是非常方便.好用的 ...

  5. [django]在virtualenv下安装的第三方库的使用方法

    在virtualenv下安装的第三方库,例如south, requests等,如果想在django中使用,需要先将库添加到settings.py的INSTALLED_APPS中, 以south, re ...

  6. 安装php扩展库

    无法加载'pdo_mysql' ,因为需要pdo这个module.PHP Warning: Cannot load module 'pdo_mysql' because required module ...

  7. 解决安装vc2005运行库时提示Command line option syntax error.Type Command/?for Help

    安装vc2005运行库时提示 这是因为它要自解压到用户的临时文件夹下,如果用户名中带中文,就会报错. 简单的解决方法是,手动解压之,再安装 当然,你也可以修改用户名或者再新建个用户.

  8. [转载~笔记]CentOS单独编译安装PHP gd库扩展

    http://www.nowamagic.net/librarys/veda/detail/2610 安装gd前置库: freetype, jpegsrc, libpng 1. freetypewge ...

  9. ubuntu下安装 openssl 开发库

    ubuntu下安装 openssl 开发库 检查是否已安装openssl: sudo apt-get install openssl 如果已安装执行以下操作:sudo apt-get install ...

随机推荐

  1. 九度OJ 1109:连通图 (最小生成树)

    时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:2783 解决:1432 题目描述: 给定一个无向图和其中的所有边,判断这个图是否所有顶点都是连通的. 输入: 每组数据的第一行是两个整数 n ...

  2. Android笔记之平移View

    方法有多种,只讲一种 使用View.setLeft和View.setRight 对于wrap_content的View,要横向平移,setRight是必要的,否则View的宽度会被改变(right应设 ...

  3. HTML初级教程

    1:标题h1~h6HTML标签有专门的标签处理你页面上的标题,它们是h1,h2,h3,h4,h5和h6,象封建社会一样,h1就是万能的君主而h6就是最底层的百姓. 注意,h1标签在一个页面只能使用一次 ...

  4. TCP与HTTP连接管理

    一. HTTP事务时延原因(HTTP权威指南 P86) 1.客户端首先需要根据URI确定WEB服务器的IP和端口号, 那么DNS解析上花的时间会很多(大多数HTTP客户端会有一个小的DNS缓存)   ...

  5. 常见的LINUX发行版安装libiconv库方法

    今天编译程序,发现程序报错,如下 cannot find -liconv collect2: ld returned 1 exit status 或者 undefined reference to ` ...

  6. hive和hbase本质区别——hbase本质是OLTP的nosql DB,而hive是OLAP 底层是hdfs,需从已有数据库同步数据到hdfs;hive可以用hbase中的数据,通过hive表映射到hbase表

    对于hbase当前noSql数据库的一种,最常见的应用场景就是采集的网页数据的存储,由于是key-value型数据库,可以再扩展到各种key-value应用场景,如日志信息的存储,对于内容信息不需要完 ...

  7. 关于Spring Security的笔记

    1.web.xml配置文件 加载Spring Security,将DelegatingFilterProxy配置在DispatcherServlet之前. <filter> <fil ...

  8. Splay模板(序列终结者)

    我只是一个存模板的,详细的请看这里http://blog.csdn.net/whai362/article/details/47298133 题目链接:http://www.codevs.cn/pro ...

  9. linux下mycat读写分离的配置

    为什么要配置读写分离,我想我就不需要再赘述了,那么在mycat下如何进行读写分离的配置,配置之后的实际效率又如何呢?我上午根据文档捣鼓和测试了一下,这里做一下记录: 最开始,我们还是要配置mysql本 ...

  10. Hihocoder 1625 : 重复字符串匹配 (KMP)

    描述 给定两个字符串A和B,请你求出字符串A最少重复几次才能使得B是A的子串. 例如A="hiho",B="hohihohi".则A重复3次之后变为" ...