SELINUX设为Disable 影响java SSH工具包Jsch 0.1.49.jar的一个案例
最近项目中遇到一个典型事件,当RHEL 的SELINUX设为DISABLE时
使用JAVA的Jsch 库调用SSH命令时将随机返回空字符串,我使用的版本是0.1.49,最新版本0.1.51未测试。
关于Jsch: http://www.jcraft.com/jsch/
为此,我特意写了一个程序测试:
package com.ibm.leo; import com.ibm.gts.cms.common.guestssh.api.GuestSshServiceFactory;
import com.ibm.gts.cms.common.guestssh.api.IGuestSshProperties;
import com.ibm.gts.cms.common.guestssh.api.IGuestSshService;
import com.ibm.gts.cms.common.guestssh.api.IScriptResponse; public class GuestSSH {
/**
* This code snippet will validate that the guestssh service remove execute will return null randomly if the selinux was disabled.
* */
public static void main(String[] args) {
try{
int sshRC=-1;
if(args.length<3){
System.out.println("Usage: java -jar testssh.jar <Host IP> <command> <count>");
System.exit(1);
} int count=Integer.parseInt(args[2]);
if(count==0) count=1; int nullCount=0;
System.out.println("start test...");
// Run the command via SSH
IGuestSshService sshService = GuestSshServiceFactory.GetService();
IGuestSshProperties props = sshService.makeGuestSshProperties();
props.setConnectTimeout(60000); // 60 seconds to establish connection with the guest
props.setCommandTimeout(60 * 60 * 1000); // 1 hour to wait for command to complete (after connection)
//props.setScriptInputStream(null); // stdin may be null, which is OK and means no stdin data
for(int i=1;i<=count;i++){
IScriptResponse response = sshService.invoke("root", args[0], 22, null, args[1], null, props);
sshRC = response.getReturnCode();
String[] stdoutLines = response.getStandardOutputLines();
if(stdoutLines[0].trim().equals("")) nullCount++;
System.out.println("Exceute count:"+i+" returnCode: "+sshRC +" return Lines:"+stdoutLines.length);
for (String line : stdoutLines) {
System.out.println("Command return: "+line);
}
}
System.out.println("End test, the total execute count is "+count+", and first line null return count is: " + nullCount);
}catch(Exception e){
System.out.println(e.getMessage());
}
} }
测试结果如下:
D:\tmp>java -jar testssh.jar 192.168.1.244 hostname 5
start test...
Exceute count:1 returnCode: 0 return Lines:1
Command return: GMTDev
Exceute count:2 returnCode: 0 return Lines:1
Command return:
Exceute count:3 returnCode: 0 return Lines:1
Command return:
Exceute count:4 returnCode: 0 return Lines:1
Command return:
Exceute count:5 returnCode: 0 return Lines:1
Command return: GMTDev
End test, the total execute count is 5, and first line null return count is: 3
从结果中可以看出,共取了5次主机名,只有两得到,3次虽然命令成功执行,但返回空值,这种情况只有当SELINUX=disabled时出现,而Enforcing和permissive返回值都正常。
或许是guestssh的一个BUG? 记录一下备查。
SELINUX设为Disable 影响java SSH工具包Jsch 0.1.49.jar的一个案例的更多相关文章
- java SSH框架详解(面试和学习都是最好的收藏资料)
Java—SSH(MVC)1. 谈谈你mvc的理解MVC是Model—View—Controler的简称.即模型—视图—控制器.MVC是一种设计模式,它强制性的把应用程序的输入.处理和输出分开.MVC ...
- Java 并发工具包 java.util.concurrent 用户指南
1. java.util.concurrent - Java 并发工具包 Java 5 添加了一个新的包到 Java 平台,java.util.concurrent 包.这个包包含有一系列能够让 Ja ...
- java ssh 面试题
1.什么是hibernate及hibernate工作原理.流程和为什么要用Hibernate? 答: 定义:Hibernate是一个开放源代码的对象关系映射(ORM)框架,它对JDBC进行了非常轻量级 ...
- Java 并发工具包 java.util.concurrent 大全
1. java.util.concurrent - Java 并发工具包 Java 5 添加了一个新的包到 Java 平台,java.util.concurrent 包.这个包包含有一系列能够让 Ja ...
- 1. java.util.concurrent - Java 并发工具包
1. java.util.concurrent - Java 并发工具包 Java 5 添加了一个新的包到 Java 平台,java.util.concurrent 包.这个包包含有一系列能够让 Ja ...
- 影响Java EE性能的十大问题(转)
本文作者是一名有10多年经验的高级系统架构师,他的主要专业领域是Java EE.中间件和JVM技术.他在性能优化和提升方面也有很深刻的见解,下面他将和大家分享一下常见的10个影响Java EE性能问题 ...
- .Net MVC 导入导出Excel总结(三种导出Excel方法,一种导入Excel方法) 通过MVC控制器导出导入Excel文件(可用于java SSH架构)
.Net MVC 导入导出Excel总结(三种导出Excel方法,一种导入Excel方法) [原文地址] 通过MVC控制器导出导入Excel文件(可用于java SSH架构) public cl ...
- Java SSH库使用简介:Apache sshd和JSch(Java Secure Channel)
1.Apache sshd Apache sshd是一个SSH协议的100%纯Java库,支持客户端和服务器.sshd库基于Apache MINA项目(可伸缩高性能的异步IO库). 官方网站:http ...
- Java ssh 访问windows/Linux
Java ssh 访问windows/Linux 工作中遇到的问题: Java code运行在一台机器上,需要远程到linux的机器同时执行多种命令.原来采用的方法是直接调用ssh命令或者调用pli ...
随机推荐
- python xml包使用记录
<?xml version="1.0" encoding="utf-8" ?> <request> <functionID> ...
- Python学习教程(learning Python)--2.3.3 Python函数型参详解
本节讨论Python下函数型参的预设值问题. Python在设计函数时,可以给型参预设缺省值,当用户调用函数时可以不输入实参.如果用户不想使用缺省预设值则需要给型参一一赋值,可以给某些型参赋值或不按型 ...
- Python学习教程(learning Python)--1.2.1 Python输出语句print基本使用
Python提供很多的内建(built-in)函数,使用者可以不用自己写代码就可以完成一个功能很强大的程序, 在Python里使用最多的(也许是)print函数主要用于用户输出信息. 基本用法:pri ...
- angularjs2 学习笔记(五) http服务
angular2的http服务是用于从后台程序获取或更新数据的一种机制,通常情况我们需要将与后台交换数据的模块做出angular服务,利用http获取更新后台数据,angular使用http的get或 ...
- VC下的人人对弈五子棋(dos)
#include"stdio.h"#include"stdlib.h"#include"string.h"#include "io ...
- C++类实现三维数组算法
在学习北京大学教授的<程序设计实习 / Practice on Programming>中,遇到了一个习题,花了很长时间研究,现在分享出来: 课题地址:https://class.cour ...
- 11G ORACLE RAC DBCA 无法识别asm磁盘组
ASM磁盘无法识别几种现象: 1) gi家目录或者其子目录权限错误 2)asm磁盘的权限错误 3)asm实例未启动或者asm磁盘组没有mount上 4)asm磁盘组资源没有在线 5)oracle用户的 ...
- iOS-添加测试设备Identifier
第一步:确认你的设备已经连接 第二步:点击xcode上"Windows"标签,选择"Devices" 第三步:在弹出的左框选择你要添加的设备.在右边框里可以找到 ...
- C#取枚举描述
一直都觉得枚举是个很不错的东西,可以给我们带来很多方便,而且也增加代码的可读性. 我在之前已经介绍过枚举的简要应用了,再次再来写下怎么获取枚举的描述. 源码如下: 首先,我们定义个含有描述的枚举类型 ...
- inout用法浅析
inout io_data; reg out_data; reg io_link; assign io_data=io_link? out_data:'bz; //当IO_data作为输入口使用时,一 ...