首页 > 解决方案 > Camel sftp - jsch 身份验证失败

问题描述

Camel sftp publickey 连接失败,并出现以下身份验证失败错误。在源系统中创建了 id_rsa 和 id_rsa.pub 和 known_hosts 文件(在 windows 和 linux 上都试过)。将 id_rsa.pub 的内容复制粘贴到目标系统的 authorized_keys 文件中。

注意:这适用于 winscp、putty 和本地 jcraft 示例代码。几个月前,这段代码运行良好。怀疑我检查的应用程序中的 jar 更改或版本冲突,但找不到任何东西。我没有办法尝试了。请帮忙。

骆驼路线地址:

sftp://user@192.168.1.1:22/messages/out?preferredAuthentications=publicKey&privateKeyFile=C:/Users/user/.ssh/id_rsa&privateKeyPassphrase=&jschLoggingLevel=INFO

错误和 JSCH 日志:

org.apache.camel.component.file.remote.SftpOperations - Using private keyfile: C:/Users/user/.ssh/id_rsa
org.apache.camel.component.file.remote.SftpOperations - Known host file not configured, using user known host file: C:\Users\user/.ssh/known_hosts
org.apache.camel.component.file.remote.SftpOperations - Using known hosts information from file: C:\Users\user/.ssh/known_hosts
org.apache.camel.component.file.remote.SftpOperations - Using StrickHostKeyChecking: no
org.apache.camel.component.file.remote.SftpOperations - Using PreferredAuthentications: publicKey
org.apache.camel.component.file.remote.SftpOperations - JSCH -> Connecting to 192.168.84.243 port 22
org.apache.camel.component.file.remote.SftpOperations - JSCH -> Connection established
org.apache.camel.component.file.remote.SftpOperations - JSCH -> Remote version string: SSH-2.0-OpenSSH_5.3
org.apache.camel.component.file.remote.SftpOperations - JSCH -> Local version string: SSH-2.0-JSCH-0.1.54
org.apache.camel.component.file.remote.SftpOperations - JSCH -> CheckCiphers: aes256-ctr,aes192-ctr,aes128-ctr,aes256-cbc,aes192-cbc,aes128-cbc,3des-ctr,arcfour,arcfour128,arcfour256
org.apache.camel.component.file.remote.SftpOperations - JSCH -> CheckKexes: diffie-hellman-group14-sha1,ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521
org.apache.camel.component.file.remote.SftpOperations - JSCH -> CheckSignatures: ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521
org.apache.camel.component.file.remote.SftpOperations - JSCH -> SSH_MSG_KEXINIT sent
org.apache.camel.component.file.remote.SftpOperations - JSCH -> SSH_MSG_KEXINIT received
org.apache.camel.component.file.remote.SftpOperations - JSCH -> kex: server: diffie-hellman-group-exchange-sha256,diffie-hellman-group-exchange-sha1,diffie-hellman-group14-sha1,diffie-hellman-group1-sha1
org.apache.camel.component.file.remote.SftpOperations - JSCH -> kex: server: ssh-rsa,ssh-dss
org.apache.camel.component.file.remote.SftpOperations - JSCH -> kex: server: aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour128,aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc,arcfour,rijndael-cbc@lysator.liu.se
org.apache.camel.component.file.remote.SftpOperations - JSCH -> kex: server: aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour128,aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc,arcfour,rijndael-cbc@lysator.liu.se
org.apache.camel.component.file.remote.SftpOperations - JSCH -> kex: server: hmac-md5,hmac-sha1,umac-64@openssh.com,hmac-sha2-256,hmac-sha2-512,hmac-ripemd160,hmac-ripemd160@openssh.com,hmac-sha1-96,hmac-md5-96
org.apache.camel.component.file.remote.SftpOperations - JSCH -> kex: server: hmac-md5,hmac-sha1,umac-64@openssh.com,hmac-sha2-256,hmac-sha2-512,hmac-ripemd160,hmac-ripemd160@openssh.com,hmac-sha1-96,hmac-md5-96
org.apache.camel.component.file.remote.SftpOperations - JSCH -> kex: server: none,zlib@openssh.com
org.apache.camel.component.file.remote.SftpOperations - JSCH -> kex: server: none,zlib@openssh.com
org.apache.camel.component.file.remote.SftpOperations - JSCH -> kex: server: 
org.apache.camel.component.file.remote.SftpOperations - JSCH -> kex: server: 
org.apache.camel.component.file.remote.SftpOperations - JSCH -> kex: client: ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group14-sha1,diffie-hellman-group-exchange-sha256,diffie-hellman-group-exchange-sha1,diffie-hellman-group1-sha1
org.apache.camel.component.file.remote.SftpOperations - JSCH -> kex: client: ssh-rsa,ssh-dss,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521
org.apache.camel.component.file.remote.SftpOperations - JSCH -> kex: client: aes128-ctr,aes128-cbc,3des-ctr,3des-cbc,blowfish-cbc,aes192-ctr,aes192-cbc,aes256-ctr,aes256-cbc
org.apache.camel.component.file.remote.SftpOperations - JSCH -> kex: client: aes128-ctr,aes128-cbc,3des-ctr,3des-cbc,blowfish-cbc,aes192-ctr,aes192-cbc,aes256-ctr,aes256-cbc
org.apache.camel.component.file.remote.SftpOperations - JSCH -> kex: client: hmac-md5,hmac-sha1,hmac-sha2-256,hmac-sha1-96,hmac-md5-96
org.apache.camel.component.file.remote.SftpOperations - JSCH -> kex: client: hmac-md5,hmac-sha1,hmac-sha2-256,hmac-sha1-96,hmac-md5-96
org.apache.camel.component.file.remote.SftpOperations - JSCH -> kex: client: none
org.apache.camel.component.file.remote.SftpOperations - JSCH -> kex: client: none
org.apache.camel.component.file.remote.SftpOperations - JSCH -> kex: client: 
org.apache.camel.component.file.remote.SftpOperations - JSCH -> kex: client: 
org.apache.camel.component.file.remote.SftpOperations - JSCH -> kex: server->client aes128-ctr hmac-md5 none
org.apache.camel.component.file.remote.SftpOperations - JSCH -> kex: client->server aes128-ctr hmac-md5 none
org.apache.camel.component.file.remote.SftpOperations - JSCH -> SSH_MSG_KEXDH_INIT sent
org.apache.camel.component.file.remote.SftpOperations - JSCH -> expecting SSH_MSG_KEXDH_REPLY
org.apache.camel.component.file.remote.SftpOperations - JSCH -> ssh_rsa_verify: signature true
org.apache.camel.component.file.remote.SftpOperations - JSCH -> Host '192.168.1.1' is known and matches the RSA host key
org.apache.camel.component.file.remote.SftpOperations - JSCH -> SSH_MSG_NEWKEYS sent
org.apache.camel.component.file.remote.SftpOperations - JSCH -> SSH_MSG_NEWKEYS received
org.apache.camel.component.file.remote.SftpOperations - JSCH -> SSH_MSG_SERVICE_REQUEST sent
org.apache.camel.component.file.remote.SftpOperations - JSCH -> SSH_MSG_SERVICE_ACCEPT received
org.apache.camel.component.file.remote.SftpOperations - JSCH -> Disconnecting from 192.168.1.1 port 22

org.apache.camel.component.file.remote.RemoteFileProducer - Could not connect to: sftp://user@192.168.1.1:22/messages/out?jschLoggingLevel=INFO&preferredAuthentications=publicKey&privateKeyFile=C%3A%2FUsers%2Fuser%2F.ssh%2Fid_rsa&privateKeyPassphrase=xxxxxx. Will try to recover.
org.apache.camel.component.file.GenericFileOperationFailedException: Cannot connect to sftp://user@192.168.1.1:22
    at org.apache.camel.component.file.remote.SftpOperations.connect(SftpOperations.java:146)
    at org.apache.camel.component.file.remote.RemoteFileProducer.connectIfNecessary(RemoteFileProducer.java:214)
    at org.apache.camel.component.file.remote.RemoteFileProducer.recoverableConnectIfNecessary(RemoteFileProducer.java:184)
    at org.apache.camel.component.file.remote.RemoteFileProducer.preWriteCheck(RemoteFileProducer.java:133)
    at org.apache.camel.component.file.GenericFileProducer.processExchange(GenericFileProducer.java:113)
    at org.apache.camel.component.file.remote.RemoteFileProducer.process(RemoteFileProducer.java:58)
    at org.apache.camel.util.AsyncProcessorConverterHelper$ProcessorToAsyncProcessorBridge.process(AsyncProcessorConverterHelper.java:61)
    at org.apache.camel.processor.SendProcessor$2.doInAsyncProducer(SendProcessor.java:173)
    at org.apache.camel.impl.ProducerCache.doInAsyncProducer(ProducerCache.java:436)
    at org.apache.camel.processor.SendProcessor.process(SendProcessor.java:168)
    at org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:77)
    at org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:542)
    at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:197)
    at org.apache.camel.processor.Pipeline.process(Pipeline.java:120)
    at org.apache.camel.processor.Pipeline.process(Pipeline.java:83)
    at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:197)
    at org.apache.camel.component.file.GenericFileConsumer.processExchange(GenericFileConsumer.java:460)
    at org.apache.camel.component.file.GenericFileConsumer.processBatch(GenericFileConsumer.java:227)
    at org.apache.camel.component.file.GenericFileConsumer.poll(GenericFileConsumer.java:191)
    at org.apache.camel.impl.ScheduledPollConsumer.doRun(ScheduledPollConsumer.java:175)
    at org.apache.camel.impl.ScheduledPollConsumer.run(ScheduledPollConsumer.java:102)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308)
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:180)
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:294)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)


Caused by: com.jcraft.jsch.JSchException: Auth fail
    at com.jcraft.jsch.Session.connect(Session.java:519)
    at org.apache.camel.component.file.remote.SftpOperations.connect(SftpOperations.java:118)
    ... 27 more

标签: authenticationsshapache-camelsftpjsch

解决方案


只是我将preferredAuthentications 作为publicKey 而不是正确的publickey。只是限制问题并浪费了 2 天。JSCH 没有记录正确的错误...


推荐阅读