ssh connection takes a long time

47 views
Skip to first unread message

Miguel González

unread,
Nov 9, 2017, 12:07:08 PM11/9/17
to sshj-users

I have this piece of code to validate a connection to a remote host, I perform more than 10 connections when I run the program and it takes 13 seconds to execute.

I have enabled Bouncy Castle as a security provider and added the corresponding jars to my classpath

Is there any way to avoid taking such a long time?



int sshTimeout = 11000;
boolean login = false;
 try {
	        	       ssh.setConnectTimeout(sshTimeout);
	        	       ssh.setTimeout(sshTimeout);
	            	   ssh.connect(host); 
	                   final Session session = ssh.startSession();
	                   try {
	                      login = true;
	                   } finally{
	                	   session.close();
	                   }
	                   ssh.disconnect();
	               } catch (Exception e) {
                              e.printStackTrace();
	                    try {
							ssh.disconnect();
						} catch (IOException e1) {
							// TODO Auto-generated catch block
							e1.printStackTrace();
						}
	               } 			

Is it something wrong with the code? or it's just a network I/O problem?

Krishnan Mahadevan

unread,
Nov 14, 2017, 11:27:21 PM11/14/17
to sshj-...@googlegroups.com

Miguel,

 

Its been a long time since I personally used sshj, so please bear with me if my question sounds weird.

I am assuming that you have already carried out passwordless setup for your remote host.

 

You could perhaps check if the time being spent is due to having to load the ~/.ssh/known_hosts file. Also you could try caching the ~/.ssh/id_dsa (or id_rsa) your keys, so that you don’t have to read from the file system for every operation and see if that helps.

 

If nothing helps then, perhaps you can create a simple reproducible test, that can be executed to recreate the problem and maybe file an issue here : https://github.com/hierynomus/sshj/issues

 

Thanks & Regards

Krishnan Mahadevan

 

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"

My Scribblings @ http://wakened-cognition.blogspot.com/

My Technical Scribbings @ http://rationaleemotions.wordpress.com/

--
You received this message because you are subscribed to the Google Groups "sshj-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sshj-users+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages