Overview
Lightd includes a built-in SFTP server that provides secure file access to container volumes. Each container gets isolated SFTP access to its volume directory with automatic credential management.Features
Secure Protocol
SSH File Transfer Protocol (SFTP) version 3
Automatic Credentials
Auto-generated or custom username/password
Path Isolation
Chrooted to container volume directory
Compatible Clients
Works with FileZilla, WinSCP, VS Code, and more
Specifications
- Protocol: SSH File Transfer Protocol (SFTP) version 3
- Port: 2022 (configurable in
config.json) - Authentication: Username/password (bcrypt hashed)
- Isolation: Each session is chrooted to the container’s volume directory
- Security: No access to host filesystem or other containers
Supported Operations
- Supported
- Not Supported
✅ File Operations
- Read, write, create, delete, rename
- List, create, delete, navigate
- Size, permissions, timestamps
- realpath, stat, lstat, fstat
Generate SFTP Credentials
Create or reset SFTP credentials for a container.Get SFTP Connection Info
Retrieve existing SFTP credentials for a container.Connecting with Clients
Command Line (sftp)
FileZilla
Configure connection
- Protocol: SFTP - SSH File Transfer Protocol
- Host: 0.0.0.0 (or your server IP)
- Port: 2022
- Logon Type: Normal
- User: Your SFTP username
- Password: Your SFTP password
VS Code Remote
WinSCP
Configure
- File protocol: SFTP
- Host name: 0.0.0.0
- Port number: 2022
- User name: Your SFTP username
- Password: Your SFTP password
SFTP Commands
Once connected, you can use standard SFTP commands:Navigation
File Operations
File Management
Information
Exit
Configuration
Editconfig.json to configure SFTP settings:
enabled- Enable/disable SFTP serverport- SFTP server port (default: 2022)host- Bind address (default: 0.0.0.0)
Security
Credential Storage
Password Hashing
Password Hashing
Passwords are hashed using bcrypt with cost factor 10 for secure storage.
Database Storage
Database Storage
Credentials stored in Sled database:
storage/sftp_credentialsUnique Credentials
Unique Credentials
Each container has unique credentials for isolation.
Path Isolation
- Sessions are chrooted to container volume directory
- Path traversal attempts are blocked
- No access to:
- Host filesystem
- Other container volumes
- Lightd configuration files
Network Security
- SFTP runs on non-standard port (2022) to avoid conflicts
- SSH protocol provides encryption in transit
- Host key generated on startup (ED25519)
Troubleshooting
Connection Timeout
Connection Timeout
Problem: FileZilla or other clients timeout after 20 secondsSolution:
- Check that lightd is running:
make run - Verify SFTP is enabled in
config.json - Check firewall allows port 2022
- Try CLI first:
sftp -P 2022 user@host
Host Key Verification Failed
Host Key Verification Failed
Problem:
WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!Solution: Remove old host key:Permission Denied
Permission Denied
Problem: Cannot read/write filesSolution:
- Verify credentials are correct
- Check container volume exists
- Ensure volume has proper permissions
Path Not Found
Path Not Found
Problem:
cd command shows “stat remote: Operation unsupported”Solution: Update to latest version where STAT/LSTAT are properly implemented.Implementation Details
Architecture
Supported SFTP Packets
| Type | Name | Description |
|---|---|---|
| 1 | SSH_FXP_INIT | Protocol initialization |
| 2 | SSH_FXP_VERSION | Version response |
| 3 | SSH_FXP_OPEN | Open file |
| 4 | SSH_FXP_CLOSE | Close file/directory |
| 5 | SSH_FXP_READ | Read from file |
| 6 | SSH_FXP_WRITE | Write to file |
| 7 | SSH_FXP_STAT | Get file attributes (follows symlinks) |
| 8 | SSH_FXP_LSTAT | Get file attributes (no symlink follow) |
| 9 | SSH_FXP_FSTAT | Get attributes by handle |
| 11 | SSH_FXP_OPENDIR | Open directory |
| 12 | SSH_FXP_READDIR | Read directory entries |
| 13 | SSH_FXP_REMOVE | Delete file |
| 14 | SSH_FXP_MKDIR | Create directory |
| 15 | SSH_FXP_RMDIR | Remove directory |
| 16 | SSH_FXP_REALPATH | Canonicalize path |
| 18 | SSH_FXP_RENAME | Rename file/directory |
File Permissions
Files and directories are created with standard Unix permissions:- Files:
0o100644(rw-r—r—) - Directories:
0o040755(rwxr-xr-x)
Performance
- Window Size: 2MB for efficient large file transfers
- Packet Size: 32KB maximum
- Timeout: 5 minutes of inactivity
- Concurrent Sessions: Unlimited (one per container)
Complete Example
Future Enhancements
- Public key authentication
- Symbolic link support
- File locking
- Resume interrupted transfers
- Bandwidth limiting
- Connection logging and auditing
- Two-factor authentication
- IP whitelisting
Compatible Clients
FileZilla
Free, cross-platform FTP/SFTP client
WinSCP
Windows SFTP and FTP client
Cyberduck
macOS and Windows file transfer client
VS Code
Remote development via SSH
JetBrains
Gateway for remote development
Command Line
sftp, scp, rsync