Linux 服务器上的 SFTP 出现错误“收到的消息太长”

发布于 2024-12-18 06:21:52 字数 1549 浏览 1 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

初吻给了烟 2024-12-25 06:21:52

将您的服务器配置为使用内部 sftp 服务器,将以下指令添加到 /etc/ssh/sshd_config

Subsystem sftp internal-sftp

这样,它就不会使用用户 shell 来启动 sftp 服务器程序。

Configure your server to use the internal sftp server adding the following directive to /etc/ssh/sshd_config:

Subsystem sftp internal-sftp

That way, it will not use the user shell to launch the sftp server program.

漆黑的白昼 2024-12-25 06:21:52

“收到的消息太长”意味着您的 SFTP 客户端从 SFTP 服务器收到了错误的数据。典型的原因是服务器上的 shell 启动脚本(.bashrc、.profile、.cshrc 等)正在生成一些输出,而您的 SFTP 客户端正在尝试将该输出解析为 SFTP 消息。您可以通过运行以下命令来检查这一点:

ssh user@remote 'echo hello'

如果这会产生除“hello”之外的任何输出,则该输出可能会阻止 SFTP 或 SCP 正常工作。

正如萨尔瓦的回答一样,您可以通过将 SSH 服务器设置为使用 internal-sftp 用于 SFTP 会话。这可以避免为 SFTP 会话启动 shell。这对 SCP 或其他通过 ssh 运行的程序(如 git 或 rsync)没有帮助。

解决此问题的另一种方法是检查 shell 启动命令,找出产生输出的内容,并防止在非交互式 SSH 会话期间发生这种情况。一个技巧是在运行产生输出的命令之前测试 TTY:

if [ -t 1 ]; then
    # standard output is a TTY
    ...
fi

"Received message too long" means that your SFTP client received bad data from the SFTP server. The typical reason is that the shell startup scripts on the server (.bashrc, .profile, .cshrc, etc.) are producing some output, and your SFTP client is trying to parse that output as an SFTP message. You can check this by running the command:

ssh user@remote 'echo hello'

If this produces any output other than the "hello", then that output would probably prevent SFTP or SCP from working properly.

As in salva's answer, you can avoid this by setting the SSH server to use internal-sftp for SFTP sessions. This avoids launching your shell for SFTP sessions. This won't help with SCP or with other programs like git or rsync which run through ssh.

The other way to fix this is to go through your shell startup commands, figure out what is producing the output, and prevent that from happening during non-interactive SSH sessions. One tip is to test for a TTY before running commands which produce output:

if [ -t 1 ]; then
    # standard output is a TTY
    ...
fi
神魇的王 2024-12-25 06:21:52

它可以通过使用internal-sftp子系统来修复。
编辑 /etc/ssh/sshd_config 并替换

子系统 sftp /usr/lib/openssh/sftp-server

by

子系统 sftp 内部 sftp

然后您需要使用以下命令重新启动 sshd 服务:

/bin/systemctl restart sshd.service

It can be fixed by using the internal-sftp subsystem.
Edit /etc/ssh/sshd_config and replace

Subsystem sftp /usr/lib/openssh/sftp-server

by

Subsystem sftp internal-sftp

Then you need to restart sshd service with this command:

/bin/systemctl restart sshd.service
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文