当前位置: 首页 > 知识库问答 >
问题:

在chroote-system上用JSch打开SFTP通道失败,出现“发送通道请求失败”,但WinSCP正常工作

司允晨
2023-03-14

为SFTP连接运行具有以下设置的SSHD:

Match User service
  ForeCommand internal-sftp
  ChrootDirectory /media
  X11Forwarding no
  AllowTcpForwarding no

现在,使用JSch连接到sshd并连接一个“sftp”通道,我将得到以下异常:

com.jcraft.jsch.jschException:无法发送通道请求

这里是我的Java代码(非常类似于表单JSch网站)

Session sshSession = JSSH.getSession(<USER>, <HOST>, 22);
sshSession.setConfig("StrictHostKeyChecking", "no");
sshSession.setConfig("HashKnownHosts", "no");
sshSession.setPassword(<PASSWORD>);
sshSession.connect(5000);

Channel channel = sshSession.openChannel("sftp");
channel.connect(); // <-- here exception is raised
ChannelSftp channelSftp = (ChannelSftp) channel;
channelSftp.put(...);

如果我在sshd配置中禁用chrootdirectory-line,那么一切工作都很好。但是我不能在以后的生产中更改这条线(它已经存在了)。

但使用WinSCP,即使在以下位置使用chrootdirectory也可以成功连接到同一SFTP服务器:

. 2018-03-09 15:46:23.745 --------------------------------------------------------------------------
. 2018-03-09 15:46:23.745 WinSCP Version 5.11 (Build 7715) (OS 6.1.7601 Service Pack 1 - Windows 7 Enterprise)
. 2018-03-09 15:46:23.745 Configuration: HKCU\Software\Martin Prikryl\WinSCP 2\
. 2018-03-09 15:46:23.745 Log level: Normal
. 2018-03-09 15:46:23.745 Local account: MichaelLindner
. 2018-03-09 15:46:23.745 Working directory: C:\Program Files (x86)\SDE\WinSCP
. 2018-03-09 15:46:23.745 Process ID: 668
. 2018-03-09 15:46:23.745 Command-line: "C:\Program Files (x86)\SDE\WinSCP\WinSCP.exe" 
. 2018-03-09 15:46:23.745 Time zone: Current: GMT+1, Standard: GMT+1 (Mitteleuropäische Zeit), DST: GMT+2 (Mitteleuropäische Sommerzeit), DST Start: 25.03.2018, DST End: 28.10.2018
. 2018-03-09 15:46:23.745 Login time: Freitag, 9. März 2018 15:46:23
. 2018-03-09 15:46:23.745 --------------------------------------------------------------------------
. 2018-03-09 15:46:23.745 Session name: service@world (dev) (Modified site)
. 2018-03-09 15:46:23.745 Host name: world.local (Port: 22)
. 2018-03-09 15:46:23.745 User name: service (Password: Yes, Key file: No, Passphrase: No)
. 2018-03-09 15:46:23.745 Tunnel: No
. 2018-03-09 15:46:23.745 Transfer Protocol: SFTP
. 2018-03-09 15:46:23.745 Ping type: Off, Ping interval: 30 sec; Timeout: 15 sec
. 2018-03-09 15:46:23.745 Disable Nagle: No
. 2018-03-09 15:46:23.745 Proxy: None
. 2018-03-09 15:46:23.745 Send buffer: 262144
. 2018-03-09 15:46:23.745 SSH protocol version: 2; Compression: No
. 2018-03-09 15:46:23.745 Bypass authentication: No
. 2018-03-09 15:46:23.745 Try agent: Yes; Agent forwarding: No; TIS/CryptoCard: No; KI: Yes; GSSAPI: Yes
. 2018-03-09 15:46:23.745 GSSAPI: Forwarding: No
. 2018-03-09 15:46:23.745 Ciphers: aes,chacha20,blowfish,3des,WARN,arcfour,des; Ssh2DES: No
. 2018-03-09 15:46:23.745 KEX: ecdh,dh-gex-sha1,dh-group14-sha1,rsa,WARN,dh-group1-sha1
. 2018-03-09 15:46:23.745 SSH Bugs: Auto,Auto,Auto,Auto,Auto,Auto,Auto,Auto,Auto,Auto,Auto,Auto,Auto
. 2018-03-09 15:46:23.745 Simple channel: Yes
. 2018-03-09 15:46:23.745 Return code variable: Autodetect; Lookup user groups: Auto
. 2018-03-09 15:46:23.745 Shell: /bin/bash
. 2018-03-09 15:46:23.745 EOL: LF, UTF: Auto
. 2018-03-09 15:46:23.745 Clear aliases: Yes, Unset nat.vars: Yes, Resolve symlinks: Yes; Follow directory symlinks: No
. 2018-03-09 15:46:23.745 LS: ls -la, Ign LS warn: Yes, Scp1 Comp: No
. 2018-03-09 15:46:23.745 SFTP Bugs: Auto,Auto
. 2018-03-09 15:46:23.745 SFTP Server: default
. 2018-03-09 15:46:23.745 Local directory: default, Remote directory: home, Update: No, Cache: Yes
. 2018-03-09 15:46:23.745 Cache directory changes: Yes, Permanent: Yes
. 2018-03-09 15:46:23.745 Recycle bin: Delete to: No, Overwritten to: No, Bin path: 
. 2018-03-09 15:46:23.745 DST mode: Unix
. 2018-03-09 15:46:23.745 --------------------------------------------------------------------------
. 2018-03-09 15:46:23.776 Looking up host "world.local" for SSH connection
. 2018-03-09 15:46:24.795 Connecting to 192.168.0.1 port 22
. 2018-03-09 15:46:24.795 We claim version: SSH-2.0-WinSCP_release_5.11
. 2018-03-09 15:46:24.904 Server version: SSH-2.0-OpenSSH_5.1
. 2018-03-09 15:46:24.904 We believe remote version has SSH-2 channel request bug
. 2018-03-09 15:46:24.904 Using SSH protocol version 2
. 2018-03-09 15:46:24.904 Have a known host key of type rsa2
. 2018-03-09 15:46:24.920 Doing Diffie-Hellman group exchange
. 2018-03-09 15:46:24.920 Doing Diffie-Hellman key exchange with hash SHA-256
. 2018-03-09 15:46:25.699 Server also has ssh-dss host key, but we don't know it
. 2018-03-09 15:46:25.699 Host key fingerprint is:
. 2018-03-09 15:46:25.699 ssh-rsa 1024 a8:d9:a6:9b:4e:2b:79:e4:bb:95:44:c3:30:19:67:f1
. 2018-03-09 15:46:25.699 Verifying host key rsa2 0x23,0xca9a71a71ca07257 1e6ec7719211f02a 601cdebf1220f2cb 8d7bdd62175fb970 02331d38e4ad39be 09b3144f9033fd22 a94f9580d1626cba c2800b02a0775292 e532e9526ffb1d31 b9de89698278bf4d 8fdbde939db8715a 288df183bb145f5d 6490c0ef62a5142d e2b9c41b05d5caf7 e52ec1c0f8a3842e b14ce962b28ecda5  with fingerprint ssh-rsa 1024 a8:d9:a6:9b:4e:2b:79:e4:bb:95:44:c3:30:19:67:f1
. 2018-03-09 15:46:25.745 Host key matches cached key
. 2018-03-09 15:46:25.745 Initialised AES-256 SDCTR client->server encryption
. 2018-03-09 15:46:25.745 Initialised HMAC-SHA1 client->server MAC algorithm
. 2018-03-09 15:46:25.745 Initialised AES-256 SDCTR server->client encryption
. 2018-03-09 15:46:25.745 Initialised HMAC-SHA1 server->client MAC algorithm
! 2018-03-09 15:46:25.745 Using username "service".
. 2018-03-09 15:46:25.761 Server offered these authentication methods: publickey,keyboard-interactive
. 2018-03-09 15:46:25.761 Attempting keyboard-interactive authentication
. 2018-03-09 15:46:25.777 Prompt (keyboard interactive, "SSH server authentication", "Using keyboard-interactive authentication.", "Password: ")
. 2018-03-09 15:46:25.777 Using stored password.
. 2018-03-09 15:46:25.808 Prompt (keyboard interactive, "SSH server authentication", <no instructions>, <no prompt>)
. 2018-03-09 15:46:25.808 Ignoring empty SSH server authentication request
. 2018-03-09 15:46:25.808 Access granted
. 2018-03-09 15:46:25.808 Opening session as main channel
. 2018-03-09 15:46:25.808 Opened main channel
. 2018-03-09 15:46:25.855 Primary command failed; attempting fallback
. 2018-03-09 15:46:25.855 Started a shell/command
. 2018-03-09 15:46:25.886 --------------------------------------------------------------------------
. 2018-03-09 15:46:25.886 Using SFTP protocol.

共有1个答案

焦苏燕
2023-03-14

WinSCP日志中的此消息表示,即使WinSCP也无法启动“SFTP”通道:

.2018-03-09 15:46:25.855主命令失败;正在尝试回退
。2018-03-09 15:46:25.855启动shell/命令

WinSCP有一个回退机制,当“SFTP”通道发生故障时。相反,它会显式地尝试在一些常见位置运行sftp-serverbinary。但这或多或少是一种攻击,您不应该试图在Java中复制这种攻击。

这不是编程问题。你最好问问超级用户。

如果确实需要重现WinSCP黑客,则需要修改JSchchannelsftp,使start方法dorequestexec('/path/to/sftp-server')而不是requestsftp(或者类似地修改requestsftp)。

 类似资料:
  • 我正在尝试调试一个远程应用程序。我已经在服务器上启动了一个SOCKS代理: ssh-D 9999主机名 然后,我尝试从eclipse调试设置连接到它,其中主机名相同,端口=9999。 但是我得到了错误: 我还更新了eclipse网络连接以允许SOCKS代理。该配置在同一网络中的不同主机名上工作。 我无法解释此错误消息。有人能帮助我哪里出错了吗?我看了看这个:SSH连接成功,但localhost端口

  • 问题内容: 尝试将文件从Windows SFTP传输到Unix服务器时,我遇到一个特殊的问题。错误“堆栈跟踪”为- 我在其他论坛上进行了大量搜索,但无法找到根本原因。我还观察到另一件事-我尝试使用SFTP的文件名是 .xml,当我将其更改为 .XML时,SFTP是“成功的”。很奇怪,无法确定问题。我正在尝试使用JSch Java API。但是我在尝试WinSCP前端时也遇到了同样的问题。 问题答案

  • 我试图连接到无法通过JSch管理的远程设备,尽管我可以使用具有相同凭据的WinSCP客户端进行连接。 该应用程序是一个基于J2EE的企业应用程序,在JBoss作为7.1.1运行,在Windows服务器上,我试图从Quartz作业连接SFTP服务器。下面是我用来验证SFTP登录的代码。 你能帮我找出这种行为的可能原因吗?

  • 问题内容: 我在Jenkins v2.19中有一个管道常规脚本。我也有一个 “ Slack Notification Plugin” v2.0.1和“ Groovy Postbuild Plugin”。 我已经成功发送了一条消息“构建已开始”和“构建已完成”(如果有的话)。 当某些构建步骤失败时,如何向Slack通道发送消息“ Build failed”? 问题答案: 您可以执行类似操作并使用tr

  • 我在用这个 将图像上传到gupshup whatsapp chatbot的格式,但图像没有被发送,它显示的错误是

  • 我试图建立一个示例hyperledger fabric环境与订购者和2个同行。我没有使用docker方法,而是运行实际的可执行文件本身。 订购者和2个对等节点成功启动。但是,通道创建失败,出现以下错误。任何帮助都将不胜感激。 ORDERR_TLS的值 orderer_tls=“--tls true--cafile/opt/gopath/src/github.com/hyperledger/fabr