473,503 Members | 1,647 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How do I connect to a server from my windows box using an id_rsa key file

112 New Member
I was wondering how I connect to a server, using a password, login and needing to look up a key in an id_rsa file?

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
  1. IgnoreHostKeyVerification hostKey = new IgnoreHostKeyVerification();
  2.         SshClient ssh = new SshClient();
  3.         ssh.connect(Initializer.server, 22, hostKey);
  4.         //Authenticate
  5.         PasswordAuthenticationClient passwordAuthenticationClient = new PasswordAuthenticationClient();
  6.         passwordAuthenticationClient.setUsername(Initializer.userName);
  7.         passwordAuthenticationClient.setPassword(Initializer.password);
  8.         int result = ssh.authenticate(passwordAuthenticationClient);
  9.         if(result != AuthenticationProtocolState.COMPLETE){
  10.                 System.out.println("Login to " + Initializer.server + ":" + " " + Initializer.userName + "/" + Initializer.password + " failed");
  11.  
  12.         }
  13.  
But now, Since i have to use the keys, I have been trying a few things, but i cant seem to get it to authenticate.

This is what I have tried so far:
Expand|Select|Wrap|Line Numbers
  1. String publicKeyPath = "C:"+File.separator+"Documents and Settings"+File.separator+"dedhia"+File.separator+"Desktop"+File.separator+"id_rsa";
  2.         File key = new File(publicKeyPath);
  3.         if(key.exists())
  4.         {
  5.             System.out.println("THE FILE " + publicKeyPath + " Does Exist");
  6.         }
  7.         else{
  8.             System.out.println("THE FILE DOES NOT EXIST" + publicKeyPath + " Does NOT Exist");
  9.         }
  10.  
  11.         Thread.sleep(3000);
  12.  
  13.         SshClient ssh = new SshClient();
  14.  
  15.         SshConnectionProperties properties = new SshConnectionProperties();
  16.         properties.setHost(Initializer.server);
  17.         properties.setPort(22);
  18.              properties.setPrefPublicKey("publicKeyPath");
  19.  
  20.         System.out.println("PUBLIC KEY IS: " + properties.getPrefPublicKey());
  21.  
  22.         System.out.println("PUBLIC KEY PATH IS: " + publicKeyPath);
  23.         System.out.println("THIS IS AFTER THE SETPREFPUBLICKEY");
  24.  
  25.         ssh.connect(properties, new HostKeyVerification() {
  26.             public boolean verifyHost(String host, SshPublicKey pk)
  27.                     throws TransportProtocolException {
  28.                 // TODO Auto-generated method stub
  29.                 System.out.println("VERIFYING HOST: " + host);
  30.                 System.out.println("PK IS: " + pk);
  31.  
  32.                 return true;
  33.             }
  34.         });
  35.         System.out.println("THIS IS AFTER THE SSH.CONNECT");
  36.  
  37.         PasswordAuthenticationClient passwordAuthenticationClient = new PasswordAuthenticationClient();
  38.         passwordAuthenticationClient.setUsername(Initializer.userName);
  39.         passwordAuthenticationClient.setPassword(Initializer.password);
  40.         int result = ssh.authenticate(passwordAuthenticationClient);
  41.         System.out.println("RESULT IS: " + result);
  42.         if(result != AuthenticationProtocolState.COMPLETE){
  43.                 System.out.println("Login to " + Initializer.server + ":" + " " + Initializer.userName + "/" + Initializer.password + " failed");
  44.  
  45.         }
  46.  
When i get print the result, it always comes as a 2, which is failed.

Please help!!

thanks
Oct 4 '12 #1
0 1536

Sign in to post your reply or Sign up for a free account.

Similar topics

4
1737
by: Emilio | last post by:
Question about Shared Sub Connect(server As , message As ) Why is in square brackets? Is it like Shared Sub Connect(server() As String, message() As String)
1
2947
by: shun | last post by:
Hello, I need an sample program to connect mysql server by using odbc. thanks in advance
1
8185
by: RadhakrishnanR | last post by:
Hi, How to copy a file from SFTP server to local PC using Batch file. Please consider that SFTP server is installed in Linux OS NOT in Windows OS. i.e. I need Batch file script to do the above...
1
3240
by: puttaramakrishna | last post by:
Hi Folks, How to connect from windows to linux using ssh without username/passwd. With this scenario, i need to write a program on python. Regards, Ramakrishna.
0
1321
by: adhimoolamd | last post by:
Dear Friend’s, I need your help’s here to print the pdf file at server side using network printers. Here I am using System.Diagnostic.process namespace to print the pdf file. The problem is...
2
9765
by: jeffhan | last post by:
we have os/400 db2 database at the backend. i installed db2 v9 connect server on one windows server which is locating the same network with database server. now how to i configure the connect...
6
1982
by: pugalenthi | last post by:
I am trying to connect to the SQL Server and then to create a database table using PHP script. The code is as follows,<job id="sqlserver1"> <script language="PHPScript"> $connection =...
14
5560
by: Peter | last post by:
..NET 3.5 I have a Windows Service application and it does remoting, but when a client incounters an error the client get the following error message "Server encountered an internal error....
6
10404
by: Jean-Marc Blaise | last post by:
Hi, I have installed DB2 9.5 directly from FP1 on Windows in custom mode with COMP=CONNECT_SUPPORT. I then added my DB2 Server license. I am surprise that db2licm refers to a DB2 Connect...
0
7201
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7083
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7278
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7328
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6988
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
5011
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4672
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
1510
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
379
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.