gpt4 book ai didi

spring - SSH访问Spring Boot应用程序

转载 作者:行者123 更新时间:2023-12-02 14:14:34 26 4
gpt4 key购买 nike

在Spring Boot 1.2.3.RELEASE上尝试在Windows 7的JDK 1.8上设置SSH。

我将application.properties配置为:

shell.ssh.port=2212
shell.ssh.enabled=true
shell.auth=simple
shell.auth.simple.user.name=user
shell.auth.simple.user.password=password

当应用程序启动并尝试通过腻子访问它时,将出现以下异常:
java.lang.IllegalStateException: No session available
at org.apache.sshd.common.AbstractSessionIoHandler.exceptionCaught(AbstractSessionIoHandler.java:52) ~[sshd-core-0.6.0.jar:0.6.0]
at org.apache.mina.core.filterchain.DefaultIoFilterChain$TailFilter.exceptionCaught(DefaultIoFilterChain.java:697) ~[mina-core-2.0.2.jar:na]
at org.apache.mina.core.filterchain.DefaultIoFilterChain.callNextExceptionCaught(DefaultIoFilterChain.java:483) [mina-core-2.0.2.jar:na]
at org.apache.mina.core.filterchain.DefaultIoFilterChain.access$1100(DefaultIoFilterChain.java:46) [mina-core-2.0.2.jar:na]
at org.apache.mina.core.filterchain.DefaultIoFilterChain$EntryImpl$1.exceptionCaught(DefaultIoFilterChain.java:791) [mina-core-2.0.2.jar:na]
at org.apache.mina.core.filterchain.IoFilterAdapter.exceptionCaught(IoFilterAdapter.java:111) [mina-core-2.0.2.jar:na]
at org.apache.mina.core.filterchain.DefaultIoFilterChain.callNextExceptionCaught(DefaultIoFilterChain.java:483) [mina-core-2.0.2.jar:na]
at org.apache.mina.core.filterchain.DefaultIoFilterChain.fireExceptionCaught(DefaultIoFilterChain.java:471) [mina-core-2.0.2.jar:na]
at org.apache.mina.core.filterchain.DefaultIoFilterChain.callNextSessionCreated(DefaultIoFilterChain.java:359) [mina-core-2.0.2.jar:na]
at org.apache.mina.core.filterchain.DefaultIoFilterChain.access$700(DefaultIoFilterChain.java:46) [mina-core-2.0.2.jar:na]
at org.apache.mina.core.filterchain.DefaultIoFilterChain$EntryImpl$1.sessionCreated(DefaultIoFilterChain.java:771) [mina-core-2.0.2.jar:na]
at org.apache.mina.core.filterchain.IoFilterAdapter.sessionCreated(IoFilterAdapter.java:79) [mina-core-2.0.2.jar:na]
at org.apache.mina.core.filterchain.DefaultIoFilterChain.callNextSessionCreated(DefaultIoFilterChain.java:357) [mina-core-2.0.2.jar:na]
at org.apache.mina.core.filterchain.DefaultIoFilterChain.fireSessionCreated(DefaultIoFilterChain.java:350) [mina-core-2.0.2.jar:na]
at org.apache.mina.core.service.IoServiceListenerSupport.fireSessionCreated(IoServiceListenerSupport.java:211) [mina-core-2.0.2.jar:na]
at org.apache.mina.core.polling.AbstractPollingIoProcessor.addNow(AbstractPollingIoProcessor.java:514) [mina-core-2.0.2.jar:na]
at org.apache.mina.core.polling.AbstractPollingIoProcessor.handleNewSessions(AbstractPollingIoProcessor.java:481) [mina-core-2.0.2.jar:na]
at org.apache.mina.core.polling.AbstractPollingIoProcessor.access$200(AbstractPollingIoProcessor.java:67) [mina-core-2.0.2.jar:na]
at org.apache.mina.core.polling.AbstractPollingIoProcessor$Processor.run(AbstractPollingIoProcessor.java:1071) [mina-core-2.0.2.jar:na]
at org.apache.mina.util.NamePreservingRunnable.run(NamePreservingRunnable.java:64) [mina-core-2.0.2.jar:na]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [na:1.8.0_31]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [na:1.8.0_31]
at java.lang.Thread.run(Thread.java:745) [na:1.8.0_31]
Caused by: java.lang.AbstractMethodError: org.apache.sshd.common.keyprovider.AbstractKeyPairProvider.loadKeys()[Ljava/security/KeyPair;
at org.apache.sshd.common.keyprovider.AbstractKeyPairProvider.getKeyTypes(AbstractKeyPairProvider.java:49) ~[sshd-core-0.6.0.jar:0.6.0]
at org.apache.sshd.server.session.ServerSession.sendKexInit(ServerSession.java:331) ~[sshd-core-0.6.0.jar:0.6.0]
at org.apache.sshd.server.session.ServerSession.<init>(ServerSession.java:92) ~[sshd-core-0.6.0.jar:0.6.0]
at org.apache.sshd.server.session.SessionFactory.doCreateSession(SessionFactory.java:43) ~[sshd-core-0.6.0.jar:0.6.0]
at org.apache.sshd.common.session.AbstractSessionFactory.createSession(AbstractSessionFactory.java:38) ~[sshd-core-0.6.0.jar:0.6.0]
at org.apache.sshd.common.AbstractSessionIoHandler.sessionCreated(AbstractSessionIoHandler.java:37) ~[sshd-core-0.6.0.jar:0.6.0]
at org.apache.mina.core.filterchain.DefaultIoFilterChain$TailFilter.sessionCreated(DefaultIoFilterChain.java:643) ~[mina-core-2.0.2.jar:na]
at org.apache.mina.core.filterchain.DefaultIoFilterChain.callNextSessionCreated(DefaultIoFilterChain.java:357) [mina-core-2.0.2.jar:na]

我在这里缺少什么吗?

谢谢。

更新:
感谢您的指导。这是我的依赖树:
[INFO] +- org.springframework.boot:spring-boot-starter-actuator:jar:1.2.3.RELEASE:compile
[INFO] | \- org.springframework.boot:spring-boot-actuator:jar:1.2.3.RELEASE:compile
[INFO] \- org.springframework.boot:spring-boot-starter-remote-shell:jar:1.2.3.RELEASE:compile
[INFO] +- org.crashub:crash.cli:jar:1.3.1:compile
[INFO] +- org.crashub:crash.connectors.ssh:jar:1.3.1:compile
[INFO] | +- org.apache.sshd:sshd-core:jar:0.6.0:compile
[INFO] | +- org.apache.sshd:sshd-pam:jar:0.11.0:compile
[INFO] | | \- net.sf.jpam:jpam:jar:1.1:compile
[INFO] | +- org.bouncycastle:bcpkix-jdk15on:jar:1.51:compile
[INFO] | \- org.apache.mina:mina-core:jar:2.0.2:compile
[INFO] +- org.crashub:crash.embed.spring:jar:1.3.1:compile
[INFO] +- org.crashub:crash.plugins.cron:jar:1.3.1:compile
[INFO] | \- it.sauronsoftware.cron4j:cron4j:jar:2.2.5:compile
[INFO] +- org.crashub:crash.plugins.mail:jar:1.3.1:compile
[INFO] | \- javax.mail:mail:jar:1.4.7:compile
[INFO] | \- javax.activation:activation:jar:1.1:compile
[INFO] +- org.crashub:crash.shell:jar:1.3.1:compile
[INFO] \- org.codehaus.groovy:groovy:jar:2.3.11:compile

所有依赖项从spring-boot-starter-remote-shell看来都是可传递的。我将尝试通过手动替代来解决。

最佳答案

我使用jdk1.8启动了一个 Spring 启动项目,添加了spring-boot-starter-remote-shell maven依赖项和您的配置,进行了调试,一切顺利。

但是 java.lang.AbstractMethodError 使我怀疑类路径问题,因此我很快在项目上运行了mvn dependency:tree,除其他外,spring-boot-starter-remote-shell:jar:1.2.3.RELEASEorg.apache.sshd:sshd-core:jar:0.11.0作为传递依赖项,如下所示。

[INFO] +- org.springframework.boot:spring-boot-starter-remote-shell:jar:1.2.3.RELEASE:compile
[INFO] | +- org.springframework.boot:spring-boot-starter-actuator:jar:1.2.3.RELEASE:compile
[INFO] | | \- org.springframework.boot:spring-boot-actuator:jar:1.2.3.RELEASE:compile
[INFO] | +- org.crashub:crash.cli:jar:1.3.1:compile
[INFO] | +- org.crashub:crash.connectors.ssh:jar:1.3.1:compile
[INFO] | | +- org.apache.sshd:sshd-core:jar:0.11.0:compile <===THIS ONE===
[INFO] | | +- org.apache.sshd:sshd-pam:jar:0.11.0:compile
[INFO] | | | \- net.sf.jpam:jpam:jar:1.1:compile
[INFO] | | +- org.bouncycastle:bcprov-jdk15on:jar:1.51:compile
[INFO] | | +- org.bouncycastle:bcpkix-jdk15on:jar:1.51:compile
[INFO] | | \- org.apache.mina:mina-core:jar:2.0.7:compile
[INFO] | +- org.crashub:crash.embed.spring:jar:1.3.1:compile
[INFO] | +- org.crashub:crash.plugins.cron:jar:1.3.1:compile
[INFO] | | \- it.sauronsoftware.cron4j:cron4j:jar:2.2.5:compile
[INFO] | +- org.crashub:crash.plugins.mail:jar:1.3.1:compile
[INFO] | | \- javax.mail:mail:jar:1.4:compile
[INFO] | | \- javax.activation:activation:jar:1.1:compile
[INFO] | +- org.crashub:crash.shell:jar:1.3.1:compile
[INFO] | \- org.codehaus.groovy:groovy:jar:2.3.11:compile

快速查看一下您的stacktrace,发现您在classpath at org.apache.sshd.common.keyprovider.AbstractKeyPairProvider.getKeyTypes(AbstractKeyPairProvider.java:49) ~[sshd-core-0.6.0.jar:0.6.0]上似乎有一个不同的版本,因此我接下来要做的是手动将此版本指定为pom中的依赖项。当我重新运行该应用程序并尝试通过SSH连接时,与您遇到的异常相同。

还要查看类, AbstractKeyPairProvider.loadKeys()方法具有不同的签名,该签名很可能会根据0.11.0协定混淆实现,例如 URLKeyPairProvider:
  • 0.6.0 protected abstract KeyPair[] loadKeys();
  • 0.11.0 public abstract Iterable<KeyPair> loadKeys();


  • 因此,您也可能无意中添加了此版本,或者您的某些其他依赖项正在引用它,从而有效地在类路径上隐藏了 0.11.0。就我而言,我启用了 spring boot actuator HTTP endpoints来确认上述内容:

    总之,检查您的依赖关系树,找出 sshd-core 0.6.0mina-core 2.0.2来自何处,并排除它们。

    关于spring - SSH访问Spring Boot应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29925324/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com