防火墙可能阻止SFTP默认端口(22)的连接,需确保端口开放。
sudo systemctl status firewalld(若未运行,可启动:sudo systemctl start firewalld)。sudo firewall-cmd --permanent --add-port=22/tcp(或直接允许sftp服务:sudo firewall-cmd --permanent --add-service=sftp)。sudo firewall-cmd --reload。SFTP依赖SSH服务运行,需确认SSH服务已启动。
sudo systemctl status sshd(若未运行,启动服务:sudo systemctl start sshd)。sudo systemctl enable sshd。SSH配置文件(/etc/ssh/sshd_config)中的SFTP子系统设置错误会导致连接失败。
sudo vi /etc/ssh/sshd_config。#并修改为正确路径):Subsystem sftp /usr/libexec/openssh/sftp-server(部分系统路径可能为/usr/lib/openssh/sftp-server,需根据实际调整)。sudo systemctl restart sshd。网络不通或端口未开放会导致连接超时。
ping [服务器IP地址](若无法ping通,需检查网络线路或服务器IP配置)。telnet [服务器IP地址] 22(若提示“Connection refused”,说明端口未开放,需检查防火墙或SSH服务)。SSH连接空闲可能导致超时,可通过调整KeepAlive参数保持连接。
/etc/ssh/sshd_config文件,添加或修改以下参数:TCPKeepAlive yes(启用TCP keepalive)、ClientAliveInterval 60(服务器每60秒向客户端发送一次保活信号)、ClientAliveCountMax 3(若连续3次未收到客户端响应,则断开连接)。sudo systemctl restart sshd。SELinux(安全增强模块)可能限制SFTP访问,需调整其策略。
sudo sestatus(若为Enforcing模式,需调整策略)。sudo setenforce 0(重启后恢复Enforcing:sudo setenforce 1)。/etc/selinux/config,将SELINUX=enforcing改为SELINUX=permissive,并重启服务器。日志文件可提供连接超量的具体原因(如认证失败、权限不足等)。
sudo journalctl -u sshd(实时日志)或sudo cat /var/log/secure(历史日志)。服务器资源(CPU、内存、磁盘空间)耗尽可能导致无法处理新连接。
top命令查看系统资源使用情况(重点关注%CPU、%MEM、load average)。若客户端网络较慢,可增加客户端的连接超时时间。
sftp命令时,添加-o ConnectTimeout=60参数(单位:秒,可根据网络情况调整):sftp -o ConnectTimeout=60 user@hostname。SSH服务的MaxStartups参数限制了并发未认证连接数,若超过限制,新连接会被拒绝。
sudo cat /etc/ssh/sshd_config | grep MaxStartups(默认可能为10:30:100,表示允许10个并发未认证连接,超过30%则开始拒绝)。sudo sed -i '/#MaxStartups 10:30:100/MaxStartups 10000/g' /etc/ssh/sshd_config。sudo systemctl restart sshd。