SSH Keys Guide
Set up SSH keys for remote backup repositories.
Overview
SSH keys allow Borg Web UI to access remote backup repositories securely without storing passwords. This is essential for:
- Backing up to remote servers
- Storing backups on NAS devices
- Cloud backup services (Hetzner, BorgBase, etc.)
- Offsite backup locations
🎯 UI-First Approach: Everything is done through the web interface - no terminal commands needed! Just click Deploy Key to Server, enter your server password, and the UI handles the rest.
Single-Key System: Borg Web UI uses one system SSH key for all remote connections, simplifying key management while maintaining security.
Quick Start (UI-Based Setup)
Everything is done through the web interface - no terminal needed!
- Go to Remote Machines page
- Click Generate System Key (one-time setup)
- Click Deploy Key to Server
- Enter your remote server details:
- Host (e.g.,
192.168.1.100) - Username (e.g.,
rootorbackup-user) - Password (used once for deployment)
- Mount point (optional, e.g.,
/mnt/remote-server) - Default path (optional, e.g.,
/backups)
- Host (e.g.,
- Click Deploy - the UI automatically installs your SSH key!
- Done! Your remote machine is now ready for backups
That’s it! No manual SSH commands needed. The key is automatically deployed and your connection is saved.
Generating SSH Keys
Via Web Interface
- Go to Remote Machines page
- Click Generate System Key (one-time setup)
- Select key type:
- ED25519 (recommended, modern, smaller)
- RSA 4096 (maximum compatibility)
- Click Generate
Note: You only need to generate the system key once. It will be used for all remote connections.
How SSH keys are stored:
- Private keys are encrypted and stored in the SQLite database (
/data/borg.db) - At container startup, the system SSH key is deployed to
/home/borg/.ssh/ - When running as root (
PUID=0), a symlink/root/.ssh→/home/borg/.sshis created automatically - During backup operations, keys are decrypted from the database and used via temporary files
/data/ssh_keys/is used only for temporary files during deployment and testing operations
Via Command Line (Alternative)
Note: The web interface is strongly recommended as it encrypts keys in the database. Manual key generation creates unencrypted filesystem keys.
# Generate key inside container (will be stored in filesystem, not database)
docker exec borg-web-ui ssh-keygen -t ed25519 -f /home/borg/.ssh/id_ed25519 -N ""
# View public key
docker exec borg-web-ui cat /home/borg/.ssh/id_ed25519.pub
Deploying SSH Keys
Method 1: Automatic Deployment via Web UI (Recommended)
The easiest way - everything is done through the interface:
- Go to Remote Machines page
- Click Deploy Key to Server button
- Fill in the deployment form:
Host: 192.168.1.100 Port: 22 Username: root Password: your-server-password Default Path: /backups (optional) Mount Point: /mnt/remote-server (optional) - Click Deploy
What happens:
- UI connects to your server using the password (SSH password authentication)
- Automatically creates
~/.ssh/directory with correct permissions - Installs your public key to
~/.ssh/authorized_keys - Saves the connection in your Remote Machines list
- You can now use SSH key authentication (no more passwords needed!)
Benefits:
- âś… No terminal commands needed
- âś… Automatic permission setting
- âś… Connection saved for future use
- âś… Password only used once for initial setup
Method 2: Manual Deployment (Alternative)
If you prefer manual deployment or password authentication is disabled:
- Get the public key from Remote Machines page
- Copy it to remote server:
# On your local machine
ssh user@remote-server
# On remote server
mkdir -p ~/.ssh
echo "ssh-ed25519 AAAAC3... borg-web-ui" >> ~/.ssh/authorized_keys
chmod 600 ~/.ssh/authorized_keys
chmod 700 ~/.ssh
Method 3: Via Control Panel
Many hosting providers and NAS systems have web interfaces to add SSH keys:
Hetzner Storage Box:
- Login to Robot panel
- Go to your Storage Box
- Add SSH key under “SSH-Keys” tab
BorgBase:
- Login to BorgBase
- Go to Account > SSH Keys
- Add your public key
Synology NAS:
- Control Panel > Terminal & SNMP
- Enable SSH service
- User > Advanced > User Home
- Upload key via File Station to
~/.ssh/authorized_keys
Testing SSH Connection
Via Web Interface
- Go to Remote Machines page
- Click Add Connection or Test Connection on an existing connection
- Enter connection details:
- Host:
remote-server.example.com - Port:
22(or custom) - Username:
backup-user
- Host:
- Click Test or Deploy
The system automatically uses your system SSH key for all connections.
Via Command Line
# Test from inside container using the deployed system key
docker exec borg-web-ui ssh -i /home/borg/.ssh/id_ed25519 user@remote-server -p 22 "echo Connection successful"
Note: Replace id_ed25519 with your key type (e.g., id_rsa).
Using SSH Keys in Repositories
When creating or importing a repository:
- Set repository location to SSH format:
user@hostname:/path/to/repo -
Borg Web UI automatically uses your system SSH key
- Examples:
backup@192.168.1.100:/mnt/backups/borg-repo user@server.example.com:~/backups/my-repo u123456@u123456.your-storagebox.de:./backup-repo
Note: The same system SSH key is used for all SSH repositories. Ensure you’ve deployed the key to all remote servers you want to access.
SSH Configuration
Custom Port
If your server uses a non-standard SSH port, specify it in the repository URL:
ssh://user@hostname:2222/path/to/repo
SSH Config File
For advanced configuration, create /home/borg/.ssh/config:
docker exec borg-web-ui tee /home/borg/.ssh/config << 'EOF'
Host backup-server
HostName server.example.com
Port 2222
User backup-user
IdentityFile /home/borg/.ssh/id_ed25519
Host *.your-storagebox.de
Port 23
IdentityFile /home/borg/.ssh/id_ed25519
EOF
Then use short names in repository URLs:
backup-server:/path/to/repo
Security Best Practices
1. Use Dedicated Backup User
Create a separate user on the remote server for backups:
# On remote server
sudo useradd -m -s /bin/bash backup-user
sudo mkdir -p /backups
sudo chown backup-user:backup-user /backups
2. Restrict SSH Key Permissions
Limit what the SSH key can do:
# In ~/.ssh/authorized_keys on remote server
command="borg serve --restrict-to-path /backups/borg-repo",restrict ssh-ed25519 AAAAC3... borg-web-ui
This:
- Only allows
borg servecommand - Restricts access to specific repository path
- Prevents shell access
3. Use Strong Passphrases (Optional)
For additional security, protect SSH keys with passphrases:
Note: Passphrase-protected keys require manual entry and are not supported by the web UI’s automated backups.
4. Regular Key Rotation
Rotate SSH keys periodically:
- Generate new key
- Deploy to servers
- Test with new key
- Remove old key from servers
- Delete old key from Borg Web UI
5. Firewall Rules
Restrict SSH access to known IP addresses:
# On remote server
sudo ufw allow from 192.168.1.0/24 to any port 22
Troubleshooting
Permission Denied (publickey)
Possible causes:
- Public key not added to remote server
- Wrong username or hostname
- SSH service not running on remote server
- Firewall blocking connection
Solutions:
# Verify SSH service is running
ssh user@remote-server "echo success"
# Check SSH key permissions
docker exec borg-web-ui ls -la /home/borg/.ssh/
# Test with verbose output
docker exec borg-web-ui ssh -vvv -i /home/borg/.ssh/id_ed25519 user@remote-server
Host Key Verification Failed
First-time connections require accepting the host key:
# Accept host key manually
docker exec -it borg-web-ui ssh-keyscan remote-server >> /home/borg/.ssh/known_hosts
Or disable host key checking (less secure):
# In SSH config
Host *
StrictHostKeyChecking no
UserKnownHostsFile=/dev/null
Connection Timeout
Possible causes:
- Firewall blocking port 22
- Wrong hostname/IP
- Server is down
Solutions:
# Test network connectivity
docker exec borg-web-ui ping -c 3 remote-server
# Test SSH port
docker exec borg-web-ui nc -zv remote-server 22
SSH Key Not Found
Verify the key exists:
# List SSH keys
docker exec borg-web-ui ls -la /home/borg/.ssh/
# Check key format (for system key)
docker exec borg-web-ui ssh-keygen -l -f /home/borg/.ssh/id_ed25519
# If running as root (PUID=0), verify symlink
docker exec borg-web-ui ls -la /root/.ssh
# Should show: /root/.ssh -> /home/borg/.ssh
Common Scenarios
Hetzner Storage Box
- Generate ED25519 key in Borg Web UI
- Copy public key
- Login to Hetzner Robot
- Go to your Storage Box
- Add SSH key under “SSH-Keys” tab
- Use repository URL:
ssh://u123456@u123456.your-storagebox.de:23/./backup-repo
Note: Hetzner uses port 23 for SSH, not port 22.
Synology NAS
- Enable SSH: Control Panel > Terminal & SNMP
- Create backup user with home directory
- Generate key in Borg Web UI
- Add public key to NAS:
ssh admin@nas-ip sudo mkdir -p /volume1/homes/backup-user/.ssh sudo vim /volume1/homes/backup-user/.ssh/authorized_keys # Paste public key sudo chown -R backup-user:users /volume1/homes/backup-user/.ssh sudo chmod 700 /volume1/homes/backup-user/.ssh sudo chmod 600 /volume1/homes/backup-user/.ssh/authorized_keys - Use repository URL:
backup-user@nas-ip:/volume1/backups/borg-repo
Raspberry Pi Remote Backup
- Set up SSH on Pi:
sudo raspi-config> Interface Options > SSH - Create backup directory:
mkdir -p ~/backups - Generate key in Borg Web UI
- Deploy key to Pi:
ssh pi@raspberry-pi mkdir -p ~/.ssh echo "your-public-key" >> ~/.ssh/authorized_keys chmod 600 ~/.ssh/authorized_keys - Use repository URL:
pi@raspberry-pi:~/backups/borg-repo
Single-Key System
Borg Web UI uses a single system SSH key for all remote connections. This simplifies key management:
- Generate one key: Create the system SSH key once via Remote Machines page
- Deploy to multiple servers: Deploy the same key to all your remote servers
- Automatic management: The system uses this key for all SSH repositories and connections
Benefits:
- Simpler management - one key to maintain
- Easier deployment - same key works everywhere
- Automatic usage - no need to select which key to use
How it works:
System SSH Key → Deployed to:
├─ Server 1 (Hetzner)
├─ Server 2 (NAS)
└─ Server 3 (Raspberry Pi)
All repositories and connections automatically use the system key.
Advanced: Custom SSH Config (Optional)
For advanced scenarios requiring different key types per host, manually configure SSH:
docker exec borg-web-ui tee -a /home/borg/.ssh/config << 'EOF'
Host special-server
HostName server.example.com
User backup
IdentityFile /home/borg/.ssh/custom_key
EOF
Note: This is rarely needed. The single system key works for nearly all use cases.
Next Steps
- Configuration Guide - Volume mounts and permissions
- Usage Guide - Create your first backup
- Notifications Setup - Get alerts for backup events