Unable to connect to SSH Server
Posted by Mohammad Jawwad on 30 November 2008 03:53 AM
An ssh server requires a valid hostname, username and password to establish a successful connection. The following
code shows how this can be achieved in Java :


String hostname = "hostname";
String username = "username";
String password = "password";
SshParameters sshParams = new SshParameters(hostname,username,password);
Ssh s = new Ssh(sshParams);
catch (Exception e)

If the server is expecting a private key for authentication the above code will fail with the following
exception :

at com.jscape.inet.ssh.Ssh.connect(Unknown Source)

An example debug output is shown below for the above exception :
message received: SSH_MSG_USERAUTH_FAILURE, authentications that may continue: publickey,gssapi-with-mic,password, partial success: false
message sent: SSH_MSG_USERAUTH_REQUEST, user: mohammaj, service: ssh-connection, method: keyboard-interactive

SSH_MSG_USERAUTH_FAILURE essentially means the authentication failed.

To avoid this you need to provide the private key (used in SSH public key authentication) as the fourth
argument of SshParameters class. This can be acheived as follows :

SshParameters sshParams = new SshParameters(hostname,username,password, new File("path"));

You will also receive the same exception if the hostname and/or username and/or password is incorrect.
(129 vote(s))
This article was helpful
This article was not helpful

Comments (0)
Post a new comment
Full Name:
CAPTCHA Verification 
Please enter the text you see in the image into the textbox below. This is required to prevent automated registrations and form submissions.

Help Desk Software by Kayako fusion