我正面临一个问题,我有一个SFTP服务器(没有SSH shell访问)。
当我从客户端机器做SFTP请求时,它工作:
sftp username@remote_IP
如果我执行SSH请求,它会挂起
ssh -l username -s remote_IP sftp
但是ssh
手册页建议
-s May be used to request invocation of a subsystem on the remote
system. Subsystems facilitate the use of SSH as a secure
transport for other applications (e.g. sftp(1)). The subsystem
is specified as the remote command.
远程服务器上的SSH服务器必须启用这个还是有其他方法可以解决这个问题?
添加详细日志....让我首先与您分享sftp
详细模式日志,其中建议:
debug1: Authentication succeeded (publickey)
debug1: fd 5 setting O_NONBLOCK
debug2: fd 6 is O_NONBLOCK
debug2: TCP receive buffer size: 49640 B
debug1: SSH receive window size: 198560 B
debug1: channel 0: new [client-session]
debug3: ssh_session2_open: channel_new: 0
debug1: send channel open 0
debug1: Entering interactive session.
debug2: callback start
debug1: ssh_session2_setup: id 0
debug1: Sending subsystem: sftp
debug1: channel request 0: subsystem
debug2: callback done
debug1: channel 0: open confirm rwindow 2097152 rmax 32768
debug2: Remote version: 3
debug3: Sent message fd 5 T:16 I:1
debug3: SSH_FXP_REALPATH . -> /root
sftp> pwd
现在我显示ssh -l username -s remote_IP sftp
debug1: Authentication succeeded (publickey).
debug1: channel 0: new [client-session]
debug3: ssh_session2_open: channel_new: 0
debug2: channel 0: send open
debug1: Entering interactive session.
debug2: callback start
debug2: client_session2_setup: id 0
debug1: Sending subsystem: sftp
debug2: channel 0: request subsystem confirm 1
debug2: fd 4 setting TCP_NODELAY
debug2: callback done
debug2: channel 0: open confirm rwindow 2097152 rmax 32768
debug2: channel_input_status_confirm: type 99 id 0
debug2: subsystem request accepted on channel 0
这是它挂的地方。
简而言之,问题是"如果SFTP工作并在服务器上启用,那么在远程服务器上调用子系统sftp
的ssh
会发生什么"?在服务器端或实际上在客户端需要什么才能使其工作?
如果我理解错了,请澄清我的基本理解。
你希望它做什么?
启动SFTP服务器。服务器等待SFTP请求,特别是SSH_FXP_INIT
。它从来没有得到过。SSH终端(ssh
)几乎不发送SFTP报文
挂起来了。如预期。
(请注意,尽管相同,SSH_FXP_INIT
是一个SFTP请求,而不是SSH请求。SSH_FXP
代表"SSHfile exchange p protocol")
你还没有真正告诉我们你想要什么。
让我猜猜。
您实际上认为SFTP是一个文本协议。您在sftp
(OpenSSH命令行SFTP客户端)中键入的命令(如rm
, put
等)是发送到服务器的真实命令。事实并非如此。SFTP是一种二进制协议。这些命令是特定SFTP客户端实现的专有命令。客户端(OpenSSH sftp
)将这些文本命令转换成二进制的SFTP报文/请求发送给服务器。然后它将来自SFTP服务器的二进制响应转换为人类可读的文本消息。
这些文本命令即使在理论上也不能与服务器进行真正的交换。简单的命令,比如rm
,就可以。但是put
或get
呢?如果执行put /local/path
, SFTP服务器如何访问本地文件进行读取?它不能。SFTP客户端执行此操作
这与FTP类似。FTP是一个文本协议。理论上,您可以通过输入命令与FTP服务器通信。您可以通过以下方式删除远程文件(例如使用DELE /path/to/file
命令)。但是你不能用这种方式上传或下载文件。这需要与本地FTP软件配合。
在服务器端或实际上在客户端需要什么才能使其工作?
您的服务器端按预期工作。但是在客户端需要一个实际的SFTP客户端。