您好我想通过java从windows连接到linux机器。我正在通过互联网和以下代码搜索:
public void testExec() throws IOException, InterruptedException{
Process p = Runtime.getRuntime().exec("ssh myhost");
PrintStream out = new PrintStream(p.getOutputStream());
BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream()));
out.println("ls -l /home/me");
while (in.ready()) {
String s = in.readLine();
System.out.println(s);
}
out.println("exit");
p.waitFor();
}
但我无法理解如何设置我的登录名和密码。有没有人尝试这种方式连接到linux,这是正确的吗?