温馨提示×

什么是debian sftp配置

小樊
40
2026-10-21 03:43:10
栏目: 智能运维

Debian SFTP 配置指的是在 Debian(或基于 Debian 的 Linux 系统,如 Ubuntu)上,配置 SFTP(SSH File Transfer Protocol) 服务,使用户可以通过 SSH 安全地进行文件上传和下载。

下面从概念 → 常见配置方式 → 示例给你一个清晰说明。


一、什么是 SFTP(在 Debian 中)

  • SFTP 不是 FTP,而是 基于 SSH 的加密文件传输协议
  • 默认使用 SSH(端口 22)
  • Debian 中通常由 OpenSSH Server 提供 SFTP 功能
  • 只要装了 openssh-server,一般就“自带”SFTP

查看是否安装:

dpkg -l | grep openssh-server

二、Debian 上常见的 SFTP 配置类型

1️⃣ 普通用户 SFTP(最简单)

  • 系统已有用户
  • 直接用 SSH 账号登录并传文件
sftp user@服务器IP

✅ 无需额外配置
❌ 用户可登录 Shell(有系统权限)


2️⃣ 限制用户只能 SFTP,不能 SSH(常用)

目的:
只让传文件,不能执行命令

配置步骤

  1. 创建用户
useradd -m sftpuser
passwd sftpuser
  1. 修改 SSH 配置
nano /etc/ssh/sshd_config

添加或修改:

Match User sftpuser
    ChrootDirectory /home/sftpuser
    ForceCommand internal-sftp
    AllowTcpForwarding no
    X11Forwarding no
  1. 修复权限(非常重要)
chown root:root /home/sftpuser
chmod 755 /home/sftpuser
mkdir /home/sftpuser/upload
chown sftpuser:sftpuser /home/sftpuser/upload
  1. 重启 SSH
systemctl restart ssh

✅ 用户只能 SFTP
✅ 被限制在 /home/sftpuser


3️⃣ 多用户 SFTP(组方式)

适合企业 / 多账号场景

Match Group sftpusers
    ChrootDirectory /sftp/%u
    ForceCommand internal-sftp

用户加入组:

usermod -aG sftpusers sftpuser

三、防火墙与端口

SFTP 默认使用 SSH 端口:

ufw allow 22/tcp

如修改端口:

Port 2222

四、常见问题

❌ 登录后立刻断开

  • ChrootDirectory 属主不是 root
  • 权限不是 755

❌ 能登录但不能写文件

  • 用户没有对子目录的写权限

❌ 仍能 SSH

  • 没加 ForceCommand internal-sftp

五、典型使用场景

  • 网站文件上传
  • 客户文件交换
  • 服务器备份
  • 替代 FTP(更安全)

如果你愿意,我可以:

  • ✅ 给你一份 完整可直接用的 Debian SFTP 配置
  • ✅ 教你 用密钥登录 SFTP
  • ✅ 配置 只读 / 只写 SFTP 用户

你现在是 个人服务器 还是 公司/生产环境?

0 踩