A Docker-based SFTP server using the atmoz/sftp image for secure file transfer with multiple user accounts.
Note: This is a small project originally created in 2020 and open-sourced in 2025. It's a simple, practical example of setting up an SFTP server with Docker that others might find useful.
- Multiple user account support with auto-generated secure passwords
- Persistent data storage using Docker volumes
- Easy user management via Ruby script
- Production-ready configuration
- Docker and Docker Compose installed
- Ruby installed (for user generation)
Generate user accounts and credentials:
ruby gen_users.rbThis creates:
users.conf- User configuration file (username:password:uid:gid:data format)users.csv- CSV file with usernames and passwords for distribution
By default, 3 users are created (user0001, user0002, user0003). Modify the USERS constant in gen_users.rb to change this.
docker compose build
docker compose up -dThe SFTP server will be available on port 22.
- Provision a VM
- Install Docker and Docker Compose
- Generate users via
ruby gen_users.rb - Copy
docker-compose.ymlandusers.confto the VM - Open port 2222 on the firewall
- Change the SSH port from 22 to 2222:
- Edit
Portin/etc/ssh/sshd_config - Restart SSH service:
service sshd restart
- Edit
- Start the SFTP server:
docker-compose up -d
- Restrict port 2222 access to specific DevOps IPs only (e.g., via VPN)
- Users are created with unique UIDs starting at 1001
- Passwords are generated using SecureRandom (20 characters)
User home directories are stored in the sftp_data Docker volume and persist across container restarts.
To add more users:
- Modify the
USERSconstant ingen_users.rb - Run
ruby gen_users.rb - Restart the container:
docker compose restart