I am trying to use this code for running unix command from java:
// Initialize a ConnBean object, parameter list is ip, username, password
ConnBean cb = new ConnBean("servername", "username","");
// Put the ConnBean instance as parameter for SSHExec static method getInstance(ConnBean) to retrieve a singleton SSHExec instance
SSHExec ssh = SSHExec.getInstance(cb);
// Connect to server
Boolean isConnected = ssh.connect();
String[] commands = new String[]{"sudo echo 'Hello command!.' > ChenTest.txt"};
CustomTask sampleTask = new ExecCommand(commands);
try {
Result result = ssh.exec(sampleTask);
} catch (TaskExecFailException e) {
System.out.println(e);
}
catch (Exception e) {
System.out.println(e);
}
When i debug my app i get "Auth fail".
I know that my server and username are correct, but not sure why can`t i connect. I have a key on this unix server ..do i need to add it somewhere in my code to make the connection succeed?