Skip to main content
The SFTP storage backend allows you to store backups on any server with SSH access. This is ideal for backing up to existing infrastructure or remote Linux/Unix systems.

Configuration

Required Settings

CLOUDSTIC_STORE
string
required
Set to sftp
CLOUDSTIC_STORE_PATH
string
required
Remote path on the SFTP server (e.g., /backup/cloudstic)
CLOUDSTIC_SFTP_HOST
string
required
SFTP server hostname or IP address
CLOUDSTIC_SFTP_USER
string
required
SSH username
CLOUDSTIC_SFTP_PORT
string
default:"22"
SSH port (default: 22)

Authentication Methods

Cloudstic supports three authentication methods for SFTP, tried in order:

Examples

# Using SSH key
export CLOUDSTIC_SFTP_HOST=backup.example.com
export CLOUDSTIC_SFTP_USER=backupuser
export CLOUDSTIC_SFTP_KEY=~/.ssh/backup_key

# Initialize repository
cloudstic init \
  -store sftp \
  -store-path /backup/cloudstic

# Backup
cloudstic backup -source local -source-path ~/Documents

Server Setup

Create Backup User

On the SFTP server, create a dedicated user for backups:
# Create user with home directory
sudo useradd -m -d /home/backupuser -s /bin/bash backupuser

# Create backup directory
sudo mkdir -p /backup/cloudstic
sudo chown backupuser:backupuser /backup/cloudstic
sudo chmod 700 /backup/cloudstic

Configure SSH Key

# Generate SSH key pair (on client)
ssh-keygen -t ed25519 -f ~/.ssh/backup_key -C "cloudstic-backup"

# Copy public key to server
ssh-copy-id -i ~/.ssh/backup_key.pub backupuser@backup.example.com

# Or manually:
# On server:
sudo -u backupuser mkdir -p /home/backupuser/.ssh
sudo -u backupuser chmod 700 /home/backupuser/.ssh
cat >> /home/backupuser/.ssh/authorized_keys << 'EOF'
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIGabc123... cloudstic-backup
EOF
sudo chown -R backupuser:backupuser /home/backupuser/.ssh
sudo chmod 600 /home/backupuser/.ssh/authorized_keys

Restrict Access (Optional)

For additional security, restrict the backup user to SFTP only:
# Edit /etc/ssh/sshd_config
sudo nano /etc/ssh/sshd_config
Add at the end:
Match User backupuser
    ForceCommand internal-sftp
    ChrootDirectory /backup
    PermitTunnel no
    AllowAgentForwarding no
    AllowTcpForwarding no
    X11Forwarding no
Restart SSH:
sudo systemctl restart sshd
With ChrootDirectory, the backup user is confined to /backup and cannot access other parts of the filesystem.

Features

Atomic Writes

The SFTP store ensures safe writes:
  1. Data is written to a temporary file with .tmp suffix
  2. PosixRename atomically moves the temp file to final location
  3. Interrupted writes never corrupt existing data

Directory Auto-Creation

The SFTP store automatically creates directories as needed:
func mkdirAllSFTP(c *sftp.Client, dir string) error
This handles:
  • Nested directory creation
  • Chroot environments with read-only parent directories
  • Race conditions with concurrent operations

Connection Management

SFTP connections are maintained for the duration of the operation:
  • Single persistent connection per operation
  • Reused for all file operations (Put, Get, List)
  • Automatically closed when operation completes

Performance

Upload Speed

SFTP performance depends on:
  • Network latency: Higher latency reduces throughput
  • CPU (encryption): SSH encryption is CPU-intensive
  • Disk I/O: Both client and server disk speed matter
Typical speeds:
  • LAN (1 Gbps): 50-100 MB/s
  • Internet (100 Mbps): 8-12 MB/s
  • High latency: Limited by round-trip time

Optimization Tips

Cloudstic already compresses data with zstd. For additional SSH-level compression:
# Add to ~/.ssh/config
Host backup.example.com
    Compression yes
    CompressionLevel 6
This can help over slow connections but adds CPU overhead.

Troubleshooting

Permission Denied

If you see “permission denied” errors:
# Test SSH connection
ssh -i ~/.ssh/backup_key backupuser@backup.example.com

# Check key permissions
chmod 600 ~/.ssh/backup_key

# Verify authorized_keys on server
ssh backupuser@backup.example.com 'cat ~/.ssh/authorized_keys'

Connection Refused

If the connection is refused:
# Test connectivity
telnet backup.example.com 22

# Check SSH service on server
sudo systemctl status sshd

# Check firewall
sudo ufw status
sudo firewall-cmd --list-all

Chroot Issues

If using ChrootDirectory, ensure:
# Chroot directory must be owned by root
sudo chown root:root /backup
sudo chmod 755 /backup

# User directory inside can be owned by user
sudo chown backupuser:backupuser /backup/cloudstic

Authentication Failed

If authentication fails with no clear error:
# Enable verbose SSH logging
ssh -vvv -i ~/.ssh/backup_key backupuser@backup.example.com

# Check server logs
sudo tail -f /var/log/auth.log  # Debian/Ubuntu
sudo tail -f /var/log/secure    # RHEL/CentOS

Slow Performance

If backups are slow:
  1. Test network speed: iperf3 -c backup.example.com
  2. Check latency: ping backup.example.com
  3. Enable compression: Add Compression yes to SSH config
  4. Use faster cipher: chacha20-poly1305@openssh.com
  5. Check disk I/O: iostat -x 1 on both client and server

Security Considerations

Key Management

  • Use separate SSH keys for backups (not your personal key)
  • Set appropriate key permissions: chmod 600 ~/.ssh/backup_key
  • Use Ed25519 keys for better security and performance
  • Rotate keys periodically

Server Hardening

# Disable password authentication for backup user
# In /etc/ssh/sshd_config:
Match User backupuser
    PasswordAuthentication no
    PubkeyAuthentication yes

Network Security

  • Use firewall rules to restrict access to backup server
  • Consider VPN for backups over untrusted networks
  • Monitor authentication logs for suspicious activity

Data at Rest

Cloudstic encrypts all data client-side before uploading:
  • Encryption: AES-256-GCM
  • Key derivation: HKDF with per-repository master key
  • Metadata: Also encrypted (except config and keys/ prefix)
Even if the SFTP server is compromised, backup data remains encrypted.

Comparison with Other Backends

SFTP Advantages:
  • Remote storage (off-site backup)
  • Accessible over network
  • No direct server access needed
Local Advantages:
  • Faster (no network overhead)
  • Simpler setup
  • No SSH configuration