SSH Key Management
Borg UI provides a centralized system for managing SSH keys to access remote repositories securely. This eliminates the need to manually configure SSH keys on the host.Overview
Borg UI uses a single system SSH key for all remote connections. This simplifies management and ensures consistent authentication across all SSH repositories.
Key Features
- Centralized Management: One system key for all SSH connections
- Encrypted Storage: Private keys encrypted in database using
SECRET_KEY - Automatic Deployment: Keys deployed to filesystem (
/home/borg/.ssh) on startup - Multiple Key Types: RSA, ED25519, ECDSA support
- Connection Testing: Verify SSH connectivity before use
- Storage Monitoring: Track remote storage usage via SSH
How It Works
- Generate or Import: Create a new key or import existing one
- Deploy to Servers: Use Quick Setup or manual deployment
- Automatic Use: Borg automatically uses the system key for SSH operations
- Persistent Storage: Keys survive container restarts
Quick Setup
Generate System Key
Click Quick Setup and choose:
- Name: Descriptive name (e.g., “Borg System Key”)
- Key Type:
ed25519(recommended) orrsa - Description: Optional notes
Deploy to Remote Server
Enter remote server credentials:
- Host: Remote server hostname/IP
- Username: SSH username
- Port: SSH port (default: 22)
- Password: One-time password for deployment
- Use SFTP Mode: Enable for Hetzner, disable for Synology
The password is only used once to deploy the public key. After deployment, all authentication uses the SSH key.
Generating SSH Keys
Generate New Key
| Type | Security | Speed | Compatibility | Recommended |
|---|---|---|---|---|
| ED25519 | Excellent | Fastest | Modern systems | ✅ Yes |
| RSA | Good | Slower | Universal | Legacy only |
| ECDSA | Good | Fast | Most systems | Alternative |
Response
Importing Existing Keys
Import from Filesystem
Request
If
public_key_path is omitted, Borg UI looks for {private_key_path}.pub- OpenSSH format (modern, recommended)
- PEM format (legacy)
Deploying Keys to Remote Servers
Quick Setup (Recommended)
Request
- Generates a new SSH key
- Deploys it to the remote server using
ssh-copy-id - Creates and tests the SSH connection
Manual Deployment
If you already have a key and want to deploy it:Request
SFTP Mode Compatibility:
true: Hetzner Storage Box, most modern serversfalse: Synology NAS, older SSH servers
-s flag) for ssh-copy-id.Default starting directory for SSH file browsing.Examples:
- Hetzner:
/(root of storage box) - Synology:
/volume1/backup - Generic:
/home/username/backup
Path prefix prepended to SSH commands (not SFTP).Use case: Synology NAS requires
/volume1 prefix for SSH but not SFTP.Logical mount point name for UI display.Examples:
/hetzner/synology/backup-server
Redeploying Keys
If you need to redeploy the system key to an existing connection:Request
- Server was rebuilt and lost authorized_keys
- Generated a new system key
- Public key was removed from server
Managing SSH Connections
List Connections
Response
Test Connection
- SSH connection succeeds
- Authentication works
- Server is reachable
Response
Refresh Storage Information
df -k on the remote server to collect storage statistics.
Response
Update Connection
Request
Delete Connection
Key Storage and Security
Encryption
Private keys are encrypted using Fernet symmetric encryption:- Encryption key: First 32 bytes of
SECRET_KEY - Algorithm: Fernet (AES-128-CBC + HMAC-SHA256)
- Storage: Database (
ssh_keystable)
- Deploying keys to remote servers
- Writing keys to
/home/borg/.sshon startup - Testing SSH connections
Filesystem Deployment
On container startup, the system SSH key is automatically deployed: Location:/home/borg/.ssh/
/app/app/scripts/deploy_ssh_key.py
Process:
- Read encrypted private key from database
- Decrypt using
SECRET_KEY - Write to
/home/borg/.ssh/id_{key_type} - Set proper permissions (600 for private, 644 for public)
- Set ownership to
borg:borg
Key Rotation
Troubleshooting
Permission Denied
Symptoms:- Verify key deployed: Check
/home/borg/.ssh/in container - Test manually:
- Check remote
~/.ssh/authorized_keys: - Verify SFTP mode setting matches server capabilities
Connection Timeout
Symptoms:- Check firewall rules
- Verify port (default: 22)
- Test connectivity:
Storage Info Unavailable
Symptoms: Storage information shows as unavailable or null. Causes:- Server restricts
dfcommand - Limited shell environment (e.g., Hetzner Storage Box)
- Path doesn’t exist
- Verify
default_pathexists on server - Test manually:
- Check server’s SSH restrictions (some providers limit commands)
Hetzner Storage Box Issues
Restricted shell environment:- Use
use_sftp_mode: true - Set
default_path: "/" - Storage info may fail due to command restrictions
Synology NAS Issues
Path prefix required:- Disable SFTP mode:
use_sftp_mode: false - May need to manually copy public key
Best Practices
Use ED25519 Keys
Use ED25519 Keys
ED25519 keys are faster, more secure, and smaller than RSA keys. Only use RSA for legacy system compatibility.
One System Key
One System Key
Borg UI enforces a single system key for simplicity. This is sufficient for most use cases and simplifies key rotation.
Backup Your SECRET_KEY
Backup Your SECRET_KEY
The
SECRET_KEY encrypts all private keys. Back it up securely:Test Before Production
Test Before Production
Always test SSH connections before creating repositories. Use the Test Connection button to verify.
Monitor Storage
Monitor Storage
Regularly refresh storage information to track remote disk usage and prevent out-of-space errors.
Secure Server Access
Secure Server Access
On remote servers:
- Disable password authentication after deploying keys
- Use non-standard SSH ports if exposed to internet
- Enable fail2ban for brute force protection
API Reference
Endpoints
| Method | Endpoint | Description |
|---|---|---|
| GET | /api/ssh-keys/system-key | Get system SSH key |
| POST | /api/ssh-keys/generate | Generate new system key |
| POST | /api/ssh-keys/import | Import existing key |
| POST | /api/ssh-keys/quick-setup | Generate and deploy key |
| POST | /api/ssh-keys/{key_id}/deploy | Deploy key to server |
| GET | /api/ssh-keys/connections | List all connections |
| POST | /api/ssh-keys/connections/{id}/test | Test connection |
| POST | /api/ssh-keys/connections/{id}/refresh-storage | Refresh storage info |
| PUT | /api/ssh-keys/connections/{id} | Update connection |
| POST | /api/ssh-keys/connections/{id}/redeploy | Redeploy key |
| DELETE | /api/ssh-keys/connections/{id} | Delete connection |
Next Steps
Create SSH Repository
Set up a repository on a remote SSH server
Environment Variables
Configure SSH-related environment variables
Troubleshooting
Resolve common SSH connection issues
API Reference
Complete API documentation