Automated Git Backup for Home Assistant
March 13, 2026
This guide explains how to set up automated nightly git backups for your Home Assistant configuration.
Overview
- Commits and pushes all config changes to GitHub daily at 3am
- Uses SSH deploy key (repo-specific, more secure than account-wide keys)
- Works with HAOS containers where filesystems are ephemeral
Prerequisites
- Home Assistant OS (HAOS)
- Terminal & SSH add-on installed
- GitHub repository for your HA config
Step 1: Create SSH Key (inside HA)
Open Settings → Add-ons → Terminal & SSH → Open Web UI and run:
mkdir -p /config/.ssh
ssh-keygen -t ed25519 -f /config/.ssh/id_ed25519 -N ""
chmod 600 /config/.ssh/id_ed25519
cat /config/.ssh/id_ed25519.pub
Copy the public key output.
Important: Use
/config/.ssh/not/root/.ssh/- the/configdirectory persists across container restarts.
Step 2: Add Deploy Key to GitHub
- Go to your repo on GitHub
- Settings → Deploy keys → Add deploy key
- Paste the public key
- Check “Allow write access”
- Save
Step 3: Configure Git Remote (inside HA)
In the Terminal add-on:
cd /config
git remote set-url origin git@github.com:USERNAME/REPO.git
Step 4: Add Shell Command
Add to configuration.yaml:
shell_command:
git_backup: >-
mkdir -p /root/.ssh &&
ssh-keyscan github.com >> /root/.ssh/known_hosts 2>/dev/null &&
cd /config &&
git add -A &&
git diff --quiet --cached || git commit -m "Automated backup $(date +%Y-%m-%d)" &&
GIT_SSH_COMMAND="ssh -i /config/.ssh/id_ed25519" git push 2>&1
This command:
- Creates SSH directory and adds GitHub’s host key (needed each container restart)
- Stages all changes
- Commits only if there are changes
- Pushes using the persistent SSH key
Step 5: Create Automation
Add to automations.yaml:
- id: 'nightly_git_backup'
alias: Nightly Git backup
description: Backup HA config to GitHub at 3am
triggers:
- trigger: time
at: '03:00:00'
actions:
- action: shell_command.git_backup
mode: single
Step 6: Protect SSH Key
Add to .gitignore:
.ssh/
Step 7: Test
- Reload shell commands: Developer Tools → YAML → Reload Shell Commands
- Test manually: Developer Tools → Services → shell_command.git_backup → Call Service
- Check the response for success or errors
Troubleshooting
”No such file or directory” for SSH key
The key must be in /config/.ssh/, not /root/.ssh/. The /root directory doesn’t persist.
”Host key verification failed”
The ssh-keyscan command in the shell command should handle this. If it persists, manually run in Terminal add-on:
ssh-keyscan github.com >> /root/.ssh/known_hosts
“Permission denied (publickey)”
- Verify the deploy key is added to GitHub with write access
- Check the key path is correct:
/config/.ssh/id_ed25519 - Verify permissions:
chmod 600 /config/.ssh/id_ed25519
Optional: Avoid GitHub Contribution Graph
If you don’t want backup commits counting as contributions, use a different email:
cd /config
git config user.email "homeassistant@noreply.local"