在 Debian 上修改 SFTP 端口,本质上是修改 OpenSSH 服务端(sshd) 的监听端口,因为 SFTP 是通过 SSH 提供的子系统实现的。
下面以 Debian 10/11/12 为例说明。
sudo nano /etc/ssh/sshd_config
找到或添加以下行(默认是 22):
#Port 22
Port 2222
✅ 建议:
Port 22,新增一行 Port 2222通常默认已启用:
Subsystem sftp /usr/lib/openssh/sftp-server
不要注释掉这一行。
ufwsudo ufw allow 2222/tcp
sudo ufw reload
iptablesiptables -A INPUT -p tcp --dport 2222 -j ACCEPT
Debian 默认不带 SELinux,如果你自己装了:
semanage port -a -t ssh_port_t -p tcp 2222
sudo systemctl restart ssh
⚠️ 注意:
sftp -P 2222 user@server_ip
或在 FileZilla 中:
2222SFTP#Port 22
Port 2222
然后:
sudo ufw delete allow 22/tcp
sudo systemctl restart ssh
❌ 不行
SFTP 没有独立端口,只能跟着 SSH 走。
如果你愿意,我可以:
直接说需求即可。