"Exhausted available authentication methods" exception while trying to create the SSHClient for SFTP using publickey authentication.
- Dominant language
- Java
- Stars
- 2.7k
- Forks
- 620
- Avg merge
- 3d 23h
- Merged PRs (30d)
- 11
Description
Hello all,
I am getting the `Exhausted available authentication methods` exception while trying to create the SSHClient for SFTP using publickey authentication.
Below is the code I am using:
```
SSHClient client = new SSHClient();
client.addHostKeyVerifier(new PromiscuousVerifier());
client.connect(remoteHost, remotePort);
client.authPublickey(username, sshPrivateKeyLocation);
SFTPClient sftpClient = sshClient.newSFTPClient();
```
Below is the Debug enabled log that I am getting:
```
2021-12-06 21:33:00.003 INFO 12738 --- [ scheduling-1] n.s.sshj.transport.random.JCERandom : Creating new SecureRandom.
2021-12-06 21:33:00.004 DEBUG 12738 --- [ scheduling-1] n.s.sshj.transport.random.JCERandom : Random creation took 0 ms
2021-12-06 21:33:00.069 DEBUG 12738 --- [ scheduling-1] net.schmizz.sshj.DefaultConfig : Available cipher factories: [aes128-cbc, aes128-ctr, aes192-cbc, aes192-ctr, aes256-cbc, aes256-ctr, aes128-gcm@openssh.com, aes256-gcm@openssh.com, blowfish-cbc, blowfish-ctr, cast128-cbc, cast128-ctr, idea-cbc, idea-ctr, serpent128-cbc, serpent128-ctr, serpent192-cbc, serpent192-ctr, serpent256-cbc, serpent256-ctr, 3des-cbc, 3des-ctr, twofish128-cbc, twofish128-ctr, twofish192-cbc, twofish192-ctr, twofish256-cbc, twofish256-ctr, twofish-cbc, arcfour, arcfour128, arcfour256]
2021-12-06 21:33:00.071 INFO 12738 --- [ scheduling-1] n.schmizz.sshj.transport.TransportImpl : Client identity string: SSH-2.0-SSHJ_0.31.0
2021-12-06 21:33:00.084 INFO 12738 --- [ scheduling-1] n.schmizz.sshj.transport.TransportImpl : Server identity string: SSH-2.0-srtSSHServer_19.00
2021-12-06 21:33:00.084 DEBUG 12738 --- [ scheduling-1] net.schmizz.concurrent.Promise : Setting <> to `null`
2021-12-06 21:33:00.084 DEBUG 12738 --- [ scheduling-1] net.schmizz.sshj.transport.KeyExchanger : Sending SSH_MSG_KEXINIT
2021-12-06 21:33:00.085 DEBUG 12738 --- [ scheduling-1] net.schmizz.concurrent.Promise : Setting <> to `SOME`
2021-12-06 21:33:00.085 DEBUG 12738 --- [ scheduling-1] net.schmizz.concurrent.Promise : Awaiting <>
2021-12-06 21:33:00.085 DEBUG 12738 --- [ reader] net.schmizz.sshj.transport.KeyExchanger : Received SSH_MSG_KEXINIT
2021-12-06 21:33:00.085 DEBUG 12738 --- [ reader] net.schmizz.sshj.transport.KeyExchanger : Negotiated algorithms: [ kex=diffie-hellman-group-exchange-sha256; sig=rsa-sha2-512; c2sCipher=aes128-cbc; s2cCipher=aes128-cbc; c2sMAC=hmac-sha1; s2cMAC=hmac-sha1; c2sComp=none; s2cComp=none; rsaSHA2Support=true ]
2021-12-06 21:33:00.086 DEBUG 12738 --- [ reader] n.s.sshj.transport.kex.DHGexSHA256 : Sending KEX_DH_GEX_REQUEST
2021-12-06 21:33:00.088 DEBUG 12738 --- [ reader] net.schmizz.sshj.transport.KeyExchanger : Received kex followup data
2021-12-06 21:33:00.088 DEBUG 12738 --- [ reader] n.s.sshj.transport.kex.DHGexSHA256 : Got message KEXDH_31
2021-12-06 21:33:00.088 DEBUG 12738 --- [ reader] n.s.sshj.transport.kex.DHGexSHA256 : Received server p bitlength 2048
2021-12-06 21:33:00.093 DEBUG 12738 --- [ reader] n.s.sshj.transport.kex.DHGexSHA256 : Sending KEX_DH_GEX_INIT
2021-12-06 21:33:00.096 DEBUG 12738 --- [ reader] net.schmizz.sshj.transport.KeyExchanger : Received kex followup data
2021-12-06 21:33:00.096 DEBUG 12738 --- [ reader] n.s.sshj.transport.kex.DHGexSHA256 : Got message KEX_DH_GEX_REPLY
2021-12-06 21:33:00.102 DEBUG 12738 --- [ reader] net.schmizz.sshj.transport.KeyExchanger : Trying to verify host key with net.schmizz.sshj.transport.verification.PromiscuousVerifier@91adeb8
2021-12-06 21:33:00.102 DEBUG 12738 --- [ reader] net.schmizz.sshj.transport.KeyExchanger : Sending SSH_MSG_NEWKEYS
2021-12-06 21:33:00.102 DEBUG 12738 --- [ reader] net.schmizz.sshj.transport.KeyExchanger : Received SSH_MSG_NEWKEYS
2021-12-06 21:33:00.103 DEBUG 12738 --- [ reader] net.schmizz.concurrent.Promise : Setting <> to `null`
2021-12-06 21:33:00.103 DEBUG 12738 --- [ reader] net.schmizz.concurrent.Promise : Setting <> to `SOME`
2021-12-06 21:33:00.103 DEBUG 12738 --- [ scheduling-1] net.schmizz.sshj.SSHClient : Key exchange took 0.019 seconds
2021-12-06 21:33:00.103 DEBUG 12738 --- [ scheduling-1] net.schmizz.sshj.SSHClient : Attempting to load key from: /root/.ssh/A010005_20211112
2021-12-06 21:33:00.104 DEBUG 12738 --- [ scheduling-1] net.schmizz.concurrent.Promise : Setting <> to `null`
2021-12-06 21:33:00.104 DEBUG 12738 --- [ scheduling-1] n.schmizz.sshj.transport.TransportImpl : Sending SSH_MSG_SERVICE_REQUEST for ssh-userauth
2021-12-06 21:33:00.104 DEBUG 12738 --- [ scheduling-1] net.schmizz.concurrent.Promise : Awaiting <>
2021-12-06 21:33:00.162 DEBUG 12738 --- [ reader] n.schmizz.sshj.transport.TransportImpl : Received SSH_MSG_IGNORE
2021-12-06 21:33:00.163 DEBUG 12738 --- [ reader] n.schmizz.sshj.transport.TransportImpl : Setting active service to ssh-userauth
2021-12-06 21:33:00.166 DEBUG 12738 --- [ reader] net.schmizz.concurrent.Promise : Setting <> to `SOME`
2021-12-06 21:33:00.167 DEBUG 12738 --- [ scheduling-1] net.schmizz.concurrent.Promise : Setting <> to `null`
2021-12-06 21:33:00.167 DEBUG 12738 --- [ scheduling-1] net.schmizz.sshj.userauth.UserAuthImpl : Trying `publickey` auth...
2021-12-06 21:33:00.167 DEBUG 12738 --- [ scheduling-1] n.s.sshj.userauth.method.AuthPublickey : Attempting authentication using PKCS8KeyFile{resource=[PrivateKeyFileResource] /root/.ssh/A010005_20211112}
2021-12-06 21:33:00.167 DEBUG 12738 --- [ scheduling-1] net.schmizz.concurrent.Promise : Awaiting <>
2021-12-06 21:33:00.185 DEBUG 12738 --- [ reader] net.schmizz.sshj.userauth.UserAuthImpl : Asking `publickey` method to handle USERAUTH_60 packet
2021-12-06 21:33:00.186 DEBUG 12738 --- [ reader] n.s.sshj.userauth.method.AuthPublickey : Key acceptable, sending signed request
2021-12-06 21:33:00.186 DEBUG 12738 --- [ reader] n.s.sshj.userauth.method.AuthPublickey : Attempting authentication using PKCS8KeyFile{resource=[PrivateKeyFileResource] /root/.ssh/A010005_20211112}
2021-12-06 21:33:00.195 DEBUG 12738 --- [ reader] n.schmizz.sshj.transport.TransportImpl : Received SSH_MSG_IGNORE
2021-12-06 21:33:00.235 DEBUG 12738 --- [ reader] net.schmizz.concurrent.Promise : Setting <> to `false`
2021-12-06 21:33:00.235 DEBUG 12738 --- [ scheduling-1] net.schmizz.sshj.userauth.UserAuthImpl : `publickey` auth failed
2021-12-06 21:33:00.235 ERROR 12738 --- [ scheduling-1] com.xxx.xxxx.service.SFTPService : Exhausted available authentication methods
```
However, on the same machine, I am able to connect via command line using the below mentioned command:
`sftp -i ~/.ssh/A010005_20211112 -P A010005@`
Please let me know in case I need to share more details to get a resolution.
Thank you in advance.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.