Deploying SFTPGo as an Azure Storage SFTP Alternative on Linux

Deploying SFTPGo as an Azure Storage SFTP Alternative on Linux

在 Linux 上部署 SFTPGo 作为 Azure Storage SFTP 的替代方案

Azure Storage SFTP is Microsoft’s managed file transfer service on top of Azure Blob Storage, convenient, but billed continuously per endpoint (roughly $0.30/hour, ~$220/month) and tied to Azure AD. SFTPGo is an open-source file transfer server offering SFTP, FTP/S, and WebDAV with pluggable storage backends (local disk, Azure Blob, S3-compatible, GCS) and no per-endpoint charge. This guide deploys SFTPGo with Docker Compose and Traefik, sets up user auth (password + SSH key + 2FA), connects S3-compatible object storage, and covers the migration path from Azure Storage SFTP. By the end, you’ll have a self-hosted file transfer server with the same capabilities at zero endpoint cost.

Azure Storage SFTP 是微软基于 Azure Blob Storage 构建的托管文件传输服务,虽然方便,但按端点持续计费(约 0.30 美元/小时,每月约 220 美元)且绑定了 Azure AD。SFTPGo 是一款开源文件传输服务器,提供 SFTP、FTP/S 和 WebDAV 功能,支持可插拔的存储后端(本地磁盘、Azure Blob、S3 兼容存储、GCS),且不收取端点费用。本指南将介绍如何使用 Docker Compose 和 Traefik 部署 SFTPGo,设置用户认证(密码 + SSH 密钥 + 双重认证),连接 S3 兼容对象存储,并涵盖从 Azure Storage SFTP 的迁移路径。完成后,你将拥有一个功能相同且零端点成本的自托管文件传输服务器。

Azure Storage SFTP → SFTPGo Mapping

Azure Storage SFTP 与 SFTPGo 对照表

Azure Storage SFTPSFTPGo EquivalentNotes
SFTP EndpointSFTPGo SFTP ServerConfigurable port, default 2022
Azure Blob StorageAzure Blob backendNative support; point at the same container, no migration needed
Azure AD AuthenticationLDAP/OIDC pluginExternal identity provider via plugin
Local UsersWeb UI / REST APIUser management
Hierarchical NamespaceVirtual directoriesNo HNS requirement
Azure MonitorBuilt-in logging + webhooks/syslog
Azure Storage SFTPSFTPGo 等效项备注
SFTP 端点SFTPGo SFTP 服务器端口可配置,默认为 2022
Azure Blob StorageAzure Blob 后端原生支持;指向同一容器,无需迁移
Azure AD 认证LDAP/OIDC 插件通过插件对接外部身份提供商
本地用户Web UI / REST API用户管理
分层命名空间 (HNS)虚拟目录无需 HNS 要求
Azure Monitor内置日志 + Webhooks/Syslog

Prerequisite: Linux server with Docker + Compose, a DNS A record for your domain, and (if migrating) an existing Azure Storage account with SFTP enabled plus the Azure CLI installed locally.

前提条件: 运行 Docker + Compose 的 Linux 服务器、指向你域名的 DNS A 记录,以及(如果需要迁移)已启用 SFTP 的现有 Azure 存储账户和本地安装的 Azure CLI。

Deploy with Docker Compose

使用 Docker Compose 部署

  1. Create the project directories: $ mkdir -p ~/sftpgo/{data,config} $ cd ~/sftpgo

  2. 创建项目目录: $ mkdir -p ~/sftpgo/{data,config} $ cd ~/sftpgo

  3. Create the environment file: $ nano .env DOMAIN=sftp.example.com LETSENCRYPT_EMAIL=admin@example.com

  4. 创建环境变量文件: $ nano .env DOMAIN=sftp.example.com LETSENCRYPT_EMAIL=admin@example.com

  5. Create the Compose manifest: $ nano docker-compose.yml (Configuration omitted for brevity, refer to original source)

  6. 创建 Compose 清单文件: $ nano docker-compose.yml (为简洁起见省略配置内容,请参考原文)

Traefik terminates TLS on 80/443 for the admin UI; SFTP/FTP/S/WebDAV listen directly on 2022/2121/10080. Port 8080 (the admin UI’s internal port) is never exposed to the host — Traefik proxies to it over the Docker network.

Traefik 在 80/443 端口为管理界面终止 TLS;SFTP/FTP/S/WebDAV 直接监听 2022/2121/10080 端口。8080 端口(管理界面的内部端口)不会暴露给宿主机——Traefik 通过 Docker 网络将其代理出去。

  1. Start the stack: $ docker compose up -d $ docker compose ps $ docker compose logs

  2. 启动服务栈: $ docker compose up -d $ docker compose ps $ docker compose logs

Initial Admin Setup

初始管理员设置

Open https://sftp.example.com/web/admin. Create the administrator: username, strong password, confirm, Create admin and Sign in. Review Server Manager → Configurations — check the SFTP, ACME, and SMTP sections match your requirements.

打开 https://sftp.example.com/web/admin。创建管理员:输入用户名、强密码、确认密码,点击“Create admin”并登录。检查 Server Manager → Configurations,确保 SFTP、ACME 和 SMTP 部分符合你的需求。

Create a User and Configure Authentication

创建用户并配置认证

  1. Password auth: Users → Add — username, password, Status: Active, File system: Local disk, Root directory: /srv/sftpgo/USERNAME. Save.

  2. SSH key auth: Generate keys and paste the public key into Users → Edit → Public keys.

  3. 2FA: Users → Edit → ACLs → Require 2FA for — select the protocols to gate.

  4. 密码认证: Users → Add — 输入用户名、密码,状态设为 Active,文件系统选 Local disk,根目录设为 /srv/sftpgo/USERNAME。保存。

  5. SSH 密钥认证: 生成密钥并将公钥粘贴到 Users → Edit → Public keys 中。

  6. 双重认证 (2FA): Users → Edit → ACLs → Require 2FA for — 选择需要开启 2FA 的协议。

Connect S3-Compatible Object Storage

连接 S3 兼容对象存储

SFTPGo supports Azure Blob directly, but also any S3-compatible provider. Go to Users → Edit → File system → Storage: S3 (Compatible). Fill in Bucket, Region, Access Key, Access Secret, and Endpoint. Enable Use path-style addressing.

SFTPGo 不仅直接支持 Azure Blob,还支持任何 S3 兼容的提供商。前往 Users → Edit → File system → Storage: S3 (Compatible)。填写存储桶名称、区域、访问密钥 (Access Key)、密钥 (Access Secret) 和端点 (Endpoint)。启用 Use path-style addressing

Migrate from Azure Storage SFTP

从 Azure Storage SFTP 迁移

Export Users: Use az storage account local-user list and show to record usernames, SSH public keys, and home directories. Recreate Users: Use the SFTPGo REST API (/api/v2/users) to programmatically recreate the user accounts based on the exported data.

导出用户: 使用 az storage account local-user listshow 命令记录用户名、SSH 公钥和主目录。 重建用户: 使用 SFTPGo REST API (/api/v2/users) 根据导出的数据以编程方式重建用户账户。