Я хочу открыть ssh
терминалом с Java, библиотекой JSch и операционной системы Ubuntu, но есть ошибка, как это:Запуск SSH на сервере SSH с помощью Java
Pseudo-terminal will not be allocated because stdin is not a terminal.
Permission denied, please try again.
Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).
Это мой код
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import com.jcraft.jsch.Channel;
import com.jcraft.jsch.ChannelExec;
import com.jcraft.jsch.JSch;
import com.jcraft.jsch.Session;
public class Basic {
public static void main(String[] args) {
String host = "dem.web.com";
String user = "app";
String password = "web";
String command1 = "ssh [email protected]";
try {
java.util.Properties config = new java.util.Properties();
config.put("StrictHostKeyChecking", "No");
JSch jsch = new JSch();
com.jcraft.jsch.Session session = jsch.getSession(user, host, 22);
session.setPassword(password);
session.setConfig(config);
session.connect();
Channel channel = session.openChannel("exec");
((ChannelExec) channel).setCommand(command1);
channel.setInputStream(null);
((ChannelExec) channel).setErrStream(System.err);
InputStream in = channel.getInputStream();
channel.connect();
byte[] tmp = new byte[1024];
while (true) {
while (in.available() > 0) {
int i = in.read(tmp, 0, 1024);
if (i < 0)
break;
System.out.print(new String(tmp, 0, i));
}
if (channel.isClosed()) {
channel=session.openChannel("exec");
break;
}
try {
Thread.sleep(1000);
} catch (Exception ee) {
}
}
channel.disconnect();
session.disconnect();
System.out.println("DONE");
} catch (Exception e) {
e.printStackTrace();
}
}
}
Есть ли кто-нибудь, кто может мне помочь? Или может быть проще? Спасибо.