I was able to log into the box before just using the password and login, but security has gotten tighter, so now we need to public/private key.
I have the keys on my pc in a file called id_rsa and id_rsa.pub.
Before, I was doing this, which worked:
Expand|Select|Wrap|Line Numbers
- IgnoreHostKeyVerification hostKey = new IgnoreHostKeyVerification();
- SshClient ssh = new SshClient();
- ssh.connect(Initializer.server, 22, hostKey);
- //Authenticate
- PasswordAuthenticationClient passwordAuthenticationClient = new PasswordAuthenticationClient();
- passwordAuthenticationClient.setUsername(Initializer.userName);
- passwordAuthenticationClient.setPassword(Initializer.password);
- int result = ssh.authenticate(passwordAuthenticationClient);
- if(result != AuthenticationProtocolState.COMPLETE){
- System.out.println("Login to " + Initializer.server + ":" + " " + Initializer.userName + "/" + Initializer.password + " failed");
- }
This is what I have tried so far:
Expand|Select|Wrap|Line Numbers
- String publicKeyPath = "C:"+File.separator+"Documents and Settings"+File.separator+"dedhia"+File.separator+"Desktop"+File.separator+"id_rsa";
- File key = new File(publicKeyPath);
- if(key.exists())
- {
- System.out.println("THE FILE " + publicKeyPath + " Does Exist");
- }
- else{
- System.out.println("THE FILE DOES NOT EXIST" + publicKeyPath + " Does NOT Exist");
- }
- Thread.sleep(3000);
- SshClient ssh = new SshClient();
- SshConnectionProperties properties = new SshConnectionProperties();
- properties.setHost(Initializer.server);
- properties.setPort(22);
- properties.setPrefPublicKey("publicKeyPath");
- System.out.println("PUBLIC KEY IS: " + properties.getPrefPublicKey());
- System.out.println("PUBLIC KEY PATH IS: " + publicKeyPath);
- System.out.println("THIS IS AFTER THE SETPREFPUBLICKEY");
- ssh.connect(properties, new HostKeyVerification() {
- public boolean verifyHost(String host, SshPublicKey pk)
- throws TransportProtocolException {
- // TODO Auto-generated method stub
- System.out.println("VERIFYING HOST: " + host);
- System.out.println("PK IS: " + pk);
- return true;
- }
- });
- System.out.println("THIS IS AFTER THE SSH.CONNECT");
- PasswordAuthenticationClient passwordAuthenticationClient = new PasswordAuthenticationClient();
- passwordAuthenticationClient.setUsername(Initializer.userName);
- passwordAuthenticationClient.setPassword(Initializer.password);
- int result = ssh.authenticate(passwordAuthenticationClient);
- System.out.println("RESULT IS: " + result);
- if(result != AuthenticationProtocolState.COMPLETE){
- System.out.println("Login to " + Initializer.server + ":" + " " + Initializer.userName + "/" + Initializer.password + " failed");
- }
Please help!!
thanks