Debian 上 SFTP 无法连接,常见原因和排查步骤如下,按从快到慢的顺序来:
ping 服务器IP
telnet 服务器IP 22
# 或
nc -vz 服务器IP 22
systemctl status ssh
如果没运行:
systemctl start ssh
systemctl enable ssh
在服务器端执行:
journalctl -u ssh -f
# 或
tail -f /var/log/auth.log
然后客户端尝试连接,看报错信息。
检查:
grep sftp /etc/ssh/sshd_config
应有:
Subsystem sftp /usr/lib/openssh/sftp-server
如果缺失或被注释:
nano /etc/ssh/sshd_config
修改后:
systemctl restart ssh
grep 用户名 /etc/passwd
shell 应为:
/bin/bash
# 或
/bin/zsh
如果是 /usr/sbin/nologin 或 /bin/false,SFTP 可能失败(除非用 internal-sftp + chroot)
iptables -L -n
ufw status
允许 22 端口:
ufw allow 22
如果使用:
ChrootDirectory /home/user
必须满足:
chown root:root /home/user
chmod 755 /home/user
| 报错 | 原因 |
|---|---|
| Connection refused | SSH 没开 / 端口错 |
| Permission denied | 密码 / 密钥 / 用户限制 |
| broken pipe | chroot 权限错 |
| timeout | 防火墙 / 网络 |
Subsystem sftp internal-sftp
Match User sftpuser
ChrootDirectory /sftp
ForceCommand internal-sftp
PasswordAuthentication yes
如果你愿意,可以把:
/etc/ssh/sshd_config 相关配置auth.log 报错片段发出来,我可以直接帮你定位。