Ubuntu 上 FileZilla 连接问题的排查与修复
一 快速判断与优先检查
sudo systemctl status ssh(或 sshd);未运行则 sudo systemctl start ssh && sudo systemctl enable ssh;未安装则 sudo apt update && sudo apt install openssh-server。sftp user@server_ip -p 22。能连上说明网络和凭据基本正常,问题多在 FileZilla 配置。sudo ufw allow ssh 或 sudo ufw allow 22/tcp;如用 FTP,还需 sudo ufw allow 21/tcp。sudo ss -tlpn | grep sshd,若不是 22,FileZilla 端口需与之匹配。ip addr 获取正确 IP,再在 FileZilla 中使用该 IP 连接。二 常见错误与对应处理
| 症状 | 可能原因 | 处理要点 |
|---|---|---|
| Connection refused(连接被拒绝) | SSH 未运行/未安装;端口不对;防火墙拒绝 | 安装并启动 openssh-server;核对端口(默认 22);sudo ufw allow ssh 或放行对应端口 |
| Connection timed out(超时) | 网络不通、端口未放行、NAT/路由限制 | ping/traceroute 检查连通;确认云安全组/本机防火墙放行端口;核对服务器 IP 与端口 |
| Authentication failed(认证失败) | 用户名/密码错误;用户被禁止登录;SFTP 与 FTP 协议/凭据混用 | 核对用户名与密码;确认使用 SFTP 协议;必要时检查服务器用户权限与登录 shell |
| Could not connect to server(无法连接服务器) | DNS 解析失败或目标不可达 | 用 IP 直连测试;检查 DNS 设置与网络连通性 |
| 数据连接已关闭/传输失败 | FTP 主动/被动模式不当;网络不稳定 | FTP 在“传输设置”尝试切换 主动/被动模式;不稳定网络可重试或更换网络 |
三 分步排查清单
sudo systemctl status ssh → 未运行则 sudo systemctl start ssh && sudo systemctl enable sshsudo apt update && sudo apt install openssh-serversudo ss -tlpn | grep sshd → 看到如 0.0.0.0:22 表示在所有地址的 22 端口监听;若端口非 22,FileZilla 端口需填写一致sudo ufw status → 无规则则 sudo ufw allow ssh(或 sudo ufw allow 22/tcp)ip addr 获取 IP;在主机用该 IP 连接sftp user@server_ip -p 22,能连说明服务器与网络正常,问题多在 FileZilla 设置或模式sudo apt-get install vsftpd && sudo systemctl start vsftpd && sudo systemctl enable vsftpd/etc/vsftpd.conf:local_enable=YES、write_enable=YES,重启服务 sudo systemctl restart vsftpd四 仍未解决时的定位技巧
sudo journalctl -u ssh -xe 或 /var/log/auth.log,可快速定位认证/连接被拒原因。ping、traceroute/mtr 检查到服务器的路径与丢包;更换网络(蜂窝/宽带)排除本地网络限制。ss -tlpn | grep ':22',确认 sshd 正在预期端口监听,避免端口冲突。