SSHlogin工作,但SFTPlogin不

我已经看到了这个post ,但没有回答我的问题,因为它已经被遗忘了。

正如标题所说,当我用腻子login到VPS时,一切正常。 但是,当通过SFTP连接FileZilla时,我总是得到一个错误: Authentication failed, cannot establish connection to the server (粗略翻译)。
我在FileZilla中使用了正确的设置,因为我3天前只有这个错误,而且之前使用它正常工作:通过端口22的SFTP。

这里是一个iptables -L
(TL; DR:接受端口20,21和22上的所有内容,以及端口1024+上的被动入站连接)

 Chain INPUT (policy ACCEPT) target prot opt source destination ACCEPT tcp -- anywhere anywhere tcp dpt:ftp ctstate ESTABLISHED /* Allow ftp connections on port 21 */ ACCEPT tcp -- anywhere anywhere tcp dpt:ftp-data ctstate RELATED,ESTABLISHED /* Allow ftp connections on port 20 */ ACCEPT tcp -- anywhere anywhere tcp spts:1024:65535 dpts:1024:65535 ctstate ESTABLISHED /* Allow passive inbound connections */ ACCEPT tcp -- anywhere anywhere tcp dpt:ssh ctstate ESTABLISHED /* Allow ftp connections on port 22 */ Chain FORWARD (policy ACCEPT) target prot opt source destination Chain OUTPUT (policy ACCEPT) target prot opt source destination ACCEPT tcp -- anywhere anywhere tcp dpt:ftp ctstate NEW,ESTABLISHED /* Allow ftp connections on port 21 */ ACCEPT tcp -- anywhere anywhere tcp dpt:ftp-data ctstate ESTABLISHED /* Allow ftp connections on port 20 */ ACCEPT tcp -- anywhere anywhere tcp spts:1024:65535 dpts:1024:65535 ctstate RELATED,ESTABLISHED /* Allow passive inbound connections */ ACCEPT tcp -- anywhere anywhere tcp dpt:ssh ctstate ESTABLISHED /* Allow ftp connections on port 22 */ 

我确实手动设置了这个,这是我的问题的根源,但没有任何改变。

我也将PasswordAuthentication yesLogLevel DEBUG为之前的线程build议,但是重新启动sshd后没有任何更改。
这里是我在/var/log/auth.log获得的内容,当我尝试连接FileZilla时:几乎没有任何与SFTPlogin相关的东西
它只包含有关我使用sudo访问文件的内容。

我不知道它是否来自FileZilla,因为auth.log没有显示与SFTP连接相关的任何内容,或者它来自于sshdconfiguration,而忽略了SFTP请求。
我似乎无法find任何东西来帮助我,你有什么build议吗?

感谢您阅读本文。

看完你的iptables -L后。 我认为你在服务器端有一个防火墙问题。 该

 ACCEPT tcp -- anywhere anywhere tcp dpt:ssh ctstate ESTABLISHED 

ESTABLISHED通常表示有效或已经build立的连接。

在你的iptables中添加这一行

 sudo iptables -A INPUT -p tcp --dport ssh -j ACCEPT 

为了易于引导iptables 我喜欢这个如何 ,这里是一个解释

或者你可以尝试一个

 sudo sh -c "iptables-save > /etc/iptables.rules" sudo iptables -F 

testing你的连接,然后你可以恢复你的规则

 iptables-restore < /etc/iptables.rules 

这可能是由echo或其他在login时写入控制台的命令引起的。 例如,我试图为一个复杂的构build过程设置环境variables,并在所有.profile文件中添加了回声,包括到.bashrc我尝试了所有的sftp客户端:filezilla,Beyond Compare突然停止工作,但没有给予帮助错误消息。 比较之后说:

 Connection failed: Failed to establish SFTP connection (error code is 103) Failed to establish SFTP connection (error code is 103) 

最后,企业IT要求我尝试WinSCP,它提供了一个有用的错误信息:

 Received too large (1701737573 B) SFTP packet. Max supported packet size is 1024000 B. The error is typically caused by message printed from startup script (like .profile). The message may start with "ente". Cannot initialize SFTP protocol. Is the host running a SFTP server? 

这给了我线索,我需要和删除线后

 echo 'entering .bashrc' 

从我的.bashrc sftp再次工作正常

对类似问题的回答也提到了这一点,以及如何检查启动脚本的输出