Closed scuhzq closed 6 years ago
Which version? What is the trace logging? Are you running in a low entropy system such as a vm?
thanks for you reply. the version is compile group: 'com.hierynomus', name: 'sshj', version: '0.23.0' I am running at local, and connect remote server(when I use ssh in iterm,is very fast)。 the log is ...
16:00:59.142 [main] INFO net.schmizz.sshj.transport.TransportImpl - Client identity string: SSH-2.0-SSHJ_0.23.0
16:00:59.152 [main] INFO net.schmizz.sshj.transport.TransportImpl - Server identity string: SSH-2.0-OpenSSH_5.3
16:00:59.152 [main] DEBUG net.schmizz.concurrent.Promise - Setting <null
16:00:59.152 [main] DEBUG net.schmizz.sshj.transport.KeyExchanger - Sending SSH_MSG_KEXINIT
16:00:59.157 [main] DEBUG net.schmizz.concurrent.Promise - Setting <SOME
16:00:59.158 [reader] DEBUG net.schmizz.sshj.transport.KeyExchanger - Received SSH_MSG_KEXINIT
16:00:59.159 [main] DEBUG net.schmizz.concurrent.Promise - Awaiting <null
16:00:59.382 [reader] DEBUG net.schmizz.concurrent.Promise - Setting <SOME
16:00:59.382 [main] DEBUG net.schmizz.sshj.SSHClient - Key exchange took 0.23 seconds
16:00:59.385 [main] DEBUG net.schmizz.concurrent.Promise - Setting <null
16:00:59.385 [main] DEBUG net.schmizz.sshj.transport.TransportImpl - Sending SSH_MSG_SERVICE_REQUEST for ssh-userauth
16:00:59.386 [main] DEBUG net.schmizz.concurrent.Promise - Awaiting <SOME
16:00:59.433 [main] DEBUG net.schmizz.sshj.transport.TransportImpl - Setting active service to ssh-userauth
16:00:59.433 [main] DEBUG net.schmizz.concurrent.Promise - Setting <null
16:00:59.434 [main] DEBUG net.schmizz.sshj.userauth.UserAuthImpl - Trying publickey
auth...
16:00:59.434 [main] DEBUG net.schmizz.sshj.userauth.method.AuthPublickey - Attempting authentication using PKCS8KeyFile{resource=[PrivateKeyFileResource] /Users/hzq/.ssh/id_rsa}
16:00:59.435 [main] DEBUG net.schmizz.concurrent.Promise - Awaiting <publickey
method to handle USERAUTH_60 packet
16:00:59.444 [reader] DEBUG net.schmizz.sshj.userauth.method.AuthPublickey - Key acceptable, sending signed request
16:00:59.444 [reader] DEBUG net.schmizz.sshj.userauth.method.AuthPublickey - Attempting authentication using PKCS8KeyFile{resource=[PrivateKeyFileResource] /Users/hzq/.ssh/id_rsa}
16:01:00.380 [reader] DEBUG net.schmizz.sshj.transport.TransportImpl - Setting active service to ssh-connection
16:01:00.380 [reader] DEBUG net.schmizz.concurrent.Promise - Setting <true
16:01:00.381 [main] DEBUG net.schmizz.sshj.userauth.UserAuthImpl - publickey
auth successful
3960
I found session.exec if very fast. but load is slow...
long time1 = System.currentTimeMillis(); ssh = new SSHClient(); long time2 = System.currentTimeMillis(); System.out.println(time2 - time1);// 2626 ssh.loadKnownHosts(); long time3 = System.currentTimeMillis(); System.out.println(time3 - time2);//594 KeyProvider keyProvider = ssh.loadKeys("/Users/hzq/.ssh/id_rsa", "xxx".toCharArray()); ssh.connect(ip, port); ssh.authPublickey("zhanqi", keyProvider); long time4 = System.currentTimeMillis(); System.out.println(time4 - time3);//594
16:04:40.496 [main] INFO net.schmizz.sshj.transport.random.BouncyCastleRandom - Generating random seed from SecureRandom. 16:04:40.505 [main] DEBUG net.schmizz.sshj.transport.random.BouncyCastleRandom - Creating random seed took 1 ms 16:04:40.773 [main] WARN net.schmizz.sshj.DefaultConfig - Illegal key size 16:04:40.773 [main] WARN net.schmizz.sshj.DefaultConfig - Illegal key size 16:04:40.774 [main] WARN net.schmizz.sshj.DefaultConfig - Illegal key size 16:04:40.775 [main] WARN net.schmizz.sshj.DefaultConfig - Illegal key size 16:04:40.780 [main] WARN net.schmizz.sshj.DefaultConfig - Illegal key size 16:04:40.845 [main] WARN net.schmizz.sshj.DefaultConfig - Illegal key size 16:04:40.845 [main] WARN net.schmizz.sshj.DefaultConfig - Illegal key size 16:04:40.845 [main] WARN net.schmizz.sshj.DefaultConfig - Illegal key size 16:04:40.845 [main] WARN net.schmizz.sshj.DefaultConfig - Illegal key size 16:04:40.877 [main] WARN net.schmizz.sshj.DefaultConfig - Illegal key size 16:04:40.878 [main] WARN net.schmizz.sshj.DefaultConfig - Illegal key size 16:04:40.880 [main] WARN net.schmizz.sshj.DefaultConfig - Illegal key size 16:04:40.880 [main] WARN net.schmizz.sshj.DefaultConfig - Illegal key size 16:04:40.881 [main] WARN net.schmizz.sshj.DefaultConfig - Illegal key size 16:04:40.885 [main] WARN net.schmizz.sshj.DefaultConfig - Illegal key size or default parameters 16:04:40.885 [main] WARN net.schmizz.sshj.DefaultConfig - Disabling high-strength ciphers: cipher strengths apparently limited by JCE policy 16:04:40.885 [main] DEBUG net.schmizz.sshj.DefaultConfig - Available cipher factories: [aes128-cbc, aes128-ctr, blowfish-cbc, cast128-cbc, cast128-ctr, idea-cbc, idea-ctr, serpent128-cbc, serpent128-ctr, 3des-cbc, 3des-ctr, twofish128-cbc, twofish128-ctr, arcfour, arcfour128] 2626 // this is the ssh = new SSHClient(); cost time
Initializing a new DefaultConfig
takes time as it builds up all the factories. The trick is that you can reuse the config across different SSHClient
s.
Does this answer your question?
@scuhzq Did that answer your question?
I init a sshClient before executing commands, so the program is not sensitive to the Initializing process.
long time1 = System.currentTimeMillis(); ssh = new SSHClient(); ssh.loadKnownHosts(); KeyProvider keyProvider = ssh.loadKeys("/Users/hzq/.ssh/id_rsa", "123".toCharArray()); ssh.connect("192.168.0.44", 22); ssh.authPublickey("zhanqi", keyProvider); long time2 = System.currentTimeMillis(); System.out.println(time2 - time1);
log is 4602ms this usage is not suittable?
and I use jsch long time1 = System.currentTimeMillis(); JSch jsch = new JSch(); jsch.addIdentity("/Users/hzq/.ssh/id_rsa", "xxx".getBytes()); session =jsch.getSession("zhanqi", "xx", xx); java.util.Properties config = new java.util.Properties(); config.put("StrictHostKeyChecking", "no"); session.setConfig(config); session.connect();
log is 2079ms