原则性的差异涉及开放源码和免费软件这两个术语。Java既不开放也不免费,而Linux坚持这两个原则,至少在理论上是这样。此外,Java倡导者也必须明白,在Linux界存在着一个明显的分歧,大部分Linux人士都非常注重“free”这个词,虽然有些人是从经济上来了解这个词,但无论怎样他们都坚持开放源码的原则。尽管Linux有向各个阶层推广的趋势,但目前来说自由软件的积极倡导者主要来自世界各大学的学生和研究人员。他们对Linux的发展是非常关键的,为开发Linux和 *** 作系统软件输送了大批的人才。
开放源码和Linux的商业价值取决于那些用Linux为市场开发产品的开发人员,以及喜欢根据自己需要用Linux对 *** 作系统进行自定义的人们。如果必要,这些人会出钱购买Linux,因为它是一种开放的源码。他们对Linux的发展也是至关重要的,否则,Linux将只是一堆计算机课程和深奥的研究课题。
使用 jsch 连接linux1:首先添加maven 依赖
<dependency>
<groupId>com.jcraft</groupId>
<artifactId>jsch</artifactId>
<version>0.1.48</version>
</dependency>
使用密码 方式连接 linux
public static String exec(String host, String user, String psw, int port,
String command) {
String result = ""
Session session = null
ChannelExec openChannel = null
try {
JSch jsch = new JSch()
session = jsch.getSession(user, host, port)
session.setPassword(psw.getBytes())
java.util.Properties config = new java.util.Properties()
config.put("StrictHostKeyChecking", "no")
session.setConfig(config)
session.connect()
openChannel = (ChannelExec) session.openChannel("exec")
openChannel.setCommand(command)
int exitStatus = openChannel.getExitStatus()
System.out.println(exitStatus)
openChannel.connect()
InputStream in = openChannel.getInputStream()
BufferedReader reader = new BufferedReader(
new InputStreamReader(in))
String buf = null
while ((buf = reader.readLine()) != null) {
result += new String(buf.getBytes("gbk"), "UTF-8")
+ "<br>\r\n"
}
} catch (JSchException | IOException e) {
e.printStackTrace()
result += e.getMessage()
} finally {
if (openChannel != null &&!openChannel.isClosed()) {
openChannel.disconnect()
}
if (session != null &&session.isConnected()) {
session.disconnect()
}
}
return result
}
String exec = exec("192.168.80.101", "root", "111", 22,"sleep 2ls")
使用 秘钥方式 连接linux
public static String exec1(String ip, String user, int port,
String privateKey, String passphrase, String command) {
String result = ""
Session session = null
ChannelExec openChannel = null
try {
JSch jsch = new JSch()
jsch.addIdentity(privateKey)
session = jsch.getSession(user, ip, port)
java.util.Properties config = new java.util.Properties()
config.put("StrictHostKeyChecking", "no")
session.setConfig(config)
session.connect()
openChannel = (ChannelExec) session.openChannel("exec")
openChannel.setCommand(command)
int exitStatus = openChannel.getExitStatus()
System.out.println(exitStatus)
openChannel.connect()
InputStream in = openChannel.getInputStream()
BufferedReader reader = new BufferedReader(
new InputStreamReader(in))
String buf = null
while ((buf = reader.readLine()) != null) {
result += new String(buf.getBytes("gbk"), "UTF-8")
+ "<br>\r\n"
}
} catch (JSchException | IOException e) {
e.printStackTrace()
result += e.getMessage()
} finally {
if (openChannel != null &&!openChannel.isClosed()) {
openChannel.disconnect()
}
if (session != null &&session.isConnected()) {
session.disconnect()
}
}
return result
}
String result=exec1("192.168.80.101", "root", 22,"C:\\Users\\ebnew\\Desktop\\office-key(1)", "", "sleep 2ls")
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)