使用命令行 SSH 调用子系统 SFTP
SSH invocation of a subsystem SFTP using command line
我在使用 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
这是它挂起的地方。
简而言之,问题是"If SFTP works and is enabled on server what happens to ssh
which is calling subsystem sftp
on remote server"?在服务器端或事实上在客户端究竟需要什么才能使其工作?
如果我理解有误,请澄清我的基本理解。
您希望它做什么?
它启动 SFTP 服务器。服务器等待 SFTP 个请求,特别是 SSH_FXP_INIT
。它永远不会得到一个。 SSH终端(ssh
)几乎不会发送SFTP包。
所以它挂了。不出所料。
(请注意,尽管如此,SSH_FXP_INIT
是 SFTP 请求,而不是 SSH 请求。SSH_FXP
代表类似“SSH file ex更改protocol")
您还没有真正向我们解释您的期望。
所以让我猜猜。
你居然相信SFTP是一个文本协议。您在 sftp
(OpenSSH 命令行 SFTP 客户端)中键入的命令(如 rm
、put
等)是发送到服务器的真实命令.他们不是。 SFTP 是一个二进制协议。这些命令是一种特定 SFTP 客户端实现的专有命令。客户端 (OpenSSH sftp
) 将这些文本命令转换为二进制 SFTP packets/requests 并将它们发送到服务器。然后它将来自 SFTP 服务器的二进制响应转换为人类可读的文本消息。
那些文本命令即使在理论上也无法与服务器进行真正的交换。像 rm
这样的简单命令就可以。但是 put
或 get
呢?如果做put /local/path
,SFTP服务器怎么访问本地文件读取呢?这不可以。 SFTP 客户端就是这样做的。
这类似于 FTP。 FTP 是一个文本协议。理论上,您可以通过键入命令与 FTP 服务器通信。例如,您可以通过这种方式删除远程文件(使用 DELE /path/to/file
命令)。但是您不能通过这种方式上传或下载文件。那需要配合本地FTP软件
What exactly is required at server end or as a matter of fact at client side to make it work?
您的服务器端工作正常。但是您需要在客户端有一个实际的 SFTP 客户端。
我在使用 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
这是它挂起的地方。
简而言之,问题是"If SFTP works and is enabled on server what happens to ssh
which is calling subsystem sftp
on remote server"?在服务器端或事实上在客户端究竟需要什么才能使其工作?
如果我理解有误,请澄清我的基本理解。
您希望它做什么?
它启动 SFTP 服务器。服务器等待 SFTP 个请求,特别是 SSH_FXP_INIT
。它永远不会得到一个。 SSH终端(ssh
)几乎不会发送SFTP包。
所以它挂了。不出所料。
(请注意,尽管如此,SSH_FXP_INIT
是 SFTP 请求,而不是 SSH 请求。SSH_FXP
代表类似“SSH file ex更改protocol")
您还没有真正向我们解释您的期望。
所以让我猜猜。
你居然相信SFTP是一个文本协议。您在 sftp
(OpenSSH 命令行 SFTP 客户端)中键入的命令(如 rm
、put
等)是发送到服务器的真实命令.他们不是。 SFTP 是一个二进制协议。这些命令是一种特定 SFTP 客户端实现的专有命令。客户端 (OpenSSH sftp
) 将这些文本命令转换为二进制 SFTP packets/requests 并将它们发送到服务器。然后它将来自 SFTP 服务器的二进制响应转换为人类可读的文本消息。
那些文本命令即使在理论上也无法与服务器进行真正的交换。像 rm
这样的简单命令就可以。但是 put
或 get
呢?如果做put /local/path
,SFTP服务器怎么访问本地文件读取呢?这不可以。 SFTP 客户端就是这样做的。
这类似于 FTP。 FTP 是一个文本协议。理论上,您可以通过键入命令与 FTP 服务器通信。例如,您可以通过这种方式删除远程文件(使用 DELE /path/to/file
命令)。但是您不能通过这种方式上传或下载文件。那需要配合本地FTP软件
What exactly is required at server end or as a matter of fact at client side to make it work?
您的服务器端工作正常。但是您需要在客户端有一个实际的 SFTP 客户端。