温馨提示×

ubuntu sftp怎么兼容windows

小樊
52
2026-10-16 23:56:02
栏目: 智能运维

在 Ubuntu 上搭建/提供 SFTP 服务,要兼容 Windows 客户端,一般不是“系统不兼容”,而是客户端、编码、权限、路径格式的问题。下面按常见场景说明怎么做。


一、Ubuntu 作为 SFTP 服务端(最常见)

1️⃣ 使用 OpenSSH(Ubuntu 默认支持)

Ubuntu 自带 openssh-server,Windows 可以直接用:

  • Windows 自带
    • Win + R → cmd
    • 命令:
      sftp user@ubuntu_ip
      
  • Windows 资源管理器
    sftp://user@ubuntu_ip
    

✅ OpenSSH 的 SFTP 天然兼容 Windows


2️⃣ 避免 Windows 客户端“连接失败”的常见坑

✅ 确保 SSH 服务开启

sudo systemctl status ssh
sudo systemctl enable ssh
sudo systemctl start ssh

✅ 防火墙允许 22 端口

sudo ufw allow 22

二、中文乱码问题(Windows 常见)

Windows 默认是 GBK / GB2312,Ubuntu 是 UTF-8

解决方案(推荐)

✅ 统一使用 UTF-8

Ubuntu 端确认:

locale

应为:

LANG=en_US.UTF-8

Windows 端:

  • 使用 WinSCP / FileZilla
  • 设置字符编码为 UTF-8

三、推荐 Windows SFTP 客户端(兼容性最好)

✅ WinSCP(强烈推荐)

  • 支持 SFTP / SCP
  • 支持 UTF-8
  • 支持 Windows 风格路径
  • 支持记住密码

下载:

https://winscp.net

✅ FileZilla

  • 跨平台
  • 支持 SFTP
  • 设置:
    站点管理 → 协议:SFTP
    

四、Linux 用户目录权限(Windows 上传失败常见)

SFTP 对用户目录权限非常严格

正确权限示例

sudo chown -R user:user /home/user
sudo chmod 755 /home/user

⚠️ 不要:

chmod 777 /home/user

会导致 SSH 拒绝登录


五、限制用户只能 SFTP(不能 SSH)

编辑:

sudo nano /etc/ssh/sshd_config

添加:

Match User sftpuser
    ChrootDirectory /home/sftpuser
    ForceCommand internal-sftp
    AllowTcpForwarding no

重启:

sudo systemctl restart ssh

六、Windows → Ubuntu 路径差异说明

Windows Ubuntu SFTP
C:\ /
\ /
盘符 无

Windows 客户端会自动转换,无需手动处理


七、如果你指的是「Ubuntu 连 Windows 的 SFTP」

Windows 需要:

  • 开启 OpenSSH Server
  • 或安装 FileZilla Server

Ubuntu 连接:

sftp user@windows_ip

总结一句话

Ubuntu 的 SFTP 本身完全兼容 Windows,关键是:用 OpenSSH + WinSCP + UTF-8 + 正确权限

如果你有具体场景(比如:只能读不能写、中文乱码、Chroot 失败),可以贴报错,我帮你精确解决。

0 踩