This guide explains how to configure a remote git repository (GitHub, GitLab, Gitea, etc.) for Oxidized configuration backups.
By default, Oxidized stores device configurations in a local git repository at /var/lib/oxidized/repo. To add redundancy and enable remote access, you can configure a remote repository to automatically receive backup commits.
- Oxidized Deployed: Run
deploy.shfirst - Remote Repository: Create a private repository on your git hosting platform
- Authentication: Configure SSH key or personal access token
cd /root/deploy-containerized-oxidized/scripts
sudo ./setup-remote-repo.shThe script will guide you through:
- Entering remote repository URL
- Configuring remote name and branch
- Testing connectivity
- Enabling automatic push (optional)
GitHub Example:
# Using GitHub CLI
gh repo create oxidized-backups --private
# Or create manually at https://github.com/new
# ✓ Set repository to PRIVATEGitLab Example:
# Create at https://gitlab.com/projects/new
# Set visibility to PRIVATE# Generate SSH key for oxidized user (UID 30000)
sudo -u "#30000" ssh-keygen -t ed25519 -C "oxidized@$(hostname)" -f /var/lib/oxidized/.ssh/id_ed25519
# Display public key to add to GitHub/GitLab
sudo cat /var/lib/oxidized/.ssh/id_ed25519.pubAdd the public key to your git hosting platform:
- GitHub: Settings → SSH and GPG keys → New SSH key
- GitLab: Preferences → SSH Keys → Add new key
cd /var/lib/oxidized/repo
# Add remote (SSH - recommended)
git remote add origin git@github.com:username/oxidized-backups.git
# OR add remote (HTTPS - requires token)
git remote add origin https://github.com/username/oxidized-backups.git
# Verify remote
git remote -vcd /var/lib/oxidized/repo
# Rename branch to main (if needed)
git branch -M main
# Push to remote
git push -u origin mainThe setup-remote-repo.sh script creates a systemd timer that pushes every 5 minutes:
# View timer status
systemctl status oxidized-git-push.timer
# View push logs
tail -f /var/lib/oxidized/data/git-push.log
# Manually trigger push
systemctl start oxidized-git-push.serviceTimer Configuration:
- Location:
/etc/systemd/system/oxidized-git-push.timer - Frequency: Every 5 minutes
- Script:
/var/lib/oxidized/scripts/git-push.sh
# Create post-commit hook
cat > /var/lib/oxidized/repo/.git/hooks/post-commit << 'EOF'
#!/bin/bash
git push origin main 2>&1 | logger -t oxidized-git-push
EOF
chmod +x /var/lib/oxidized/repo/.git/hooks/post-commit
chown 30000:30000 /var/lib/oxidized/repo/.git/hooks/post-commitNote: Hooks push immediately after each commit, which may be excessive for high-frequency backups.
Advantages:
- More secure
- No token expiration
- Simpler setup
Setup:
# Generate key
sudo -u "#30000" ssh-keygen -t ed25519 -f /var/lib/oxidized/.ssh/id_ed25519
# Add public key to git hosting platform
sudo cat /var/lib/oxidized/.ssh/id_ed25519.pub
# Use SSH URL
git remote add origin git@github.com:username/oxidized-backups.gitAdvantages:
- Works behind restrictive firewalls
- Can be scoped/limited
Setup:
# Create token at git hosting platform
# GitHub: Settings → Developer settings → Personal access tokens → Tokens (classic)
# Scope: repo (Full control of private repositories)
# Configure git credential helper
cd /var/lib/oxidized/repo
git config credential.helper store
# First push will prompt for credentials
# Username: your-username
# Password: <paste-token>
git push -u origin mainSecurity Note: Tokens are stored in plaintext in ~/.git-credentials. Use SSH keys for better security.
CRITICAL: Always set your remote repository to PRIVATE
Device configurations may contain:
- IP addresses and network topology
- Device models and versions
- Interface configurations
- Potentially sensitive comments
GitHub:
gh repo view username/oxidized-backups --json visibility
# Should show: "visibility": "PRIVATE"GitLab:
- Navigate to: Settings → General → Visibility
- Should be: Private
# Test SSH connection
sudo -u "#30000" ssh -T git@github.com
# Should see: "Hi username! You've successfully authenticated"If fails:
# Check SSH key permissions
ls -la /var/lib/oxidized/.ssh/
# Should be: drwx------ (700) for directory, -rw------- (600) for private key
# Fix permissions if needed
chown -R 30000:30000 /var/lib/oxidized/.ssh/
chmod 700 /var/lib/oxidized/.ssh/
chmod 600 /var/lib/oxidized/.ssh/id_ed25519
chmod 644 /var/lib/oxidized/.ssh/id_ed25519.pub- Verify repository exists: Visit URL in browser
- Check remote URL:
git remote get-url origin - Ensure you have write access to repository
# Check timer status
systemctl status oxidized-git-push.timer
# If inactive, enable and start
systemctl enable --now oxidized-git-push.timer
# View recent timer executions
journalctl -u oxidized-git-push.service -n 50If remote has changes not in local:
cd /var/lib/oxidized/repo
# Fetch remote changes
git fetch origin
# Merge or rebase
git pull origin main --rebase
# Push local commits
git push origin maincd /var/lib/oxidized/repo
git log origin/main -1 --format="%ar: %s"# Watch push log
tail -f /var/lib/oxidized/data/git-push.log
# View systemd journal
journalctl -u oxidized-git-push.service -fcd /var/lib/oxidized/repo
git log origin/main..HEAD --oneline- Local Repository:
/var/lib/oxidized/repo(primary) - Remote Repository: GitHub/GitLab (redundancy)
- Push Frequency: Every 5 minutes (systemd timer)
- Backup Retention: Unlimited (full git history)
You can configure multiple remote repositories for additional redundancy:
cd /var/lib/oxidized/repo
# Add secondary remote
git remote add gitlab git@gitlab.com:username/oxidized-backups.git
# Push to both remotes
git push origin main
git push gitlab main
# Configure push to all remotes
git remote set-url --add --push origin git@github.com:username/oxidized-backups.git
git remote set-url --add --push origin git@gitlab.com:username/oxidized-backups.git
# Now 'git push origin' pushes to both- Always use private repositories
- Use SSH keys instead of tokens when possible
- Limit token scope to minimum required permissions
- Rotate credentials periodically
- Enable 2FA on git hosting account
- Use dedicated git account for automation
- Review
.gitignoreto exclude sensitive files
You can use the remote repository for:
- Compliance auditing: Track configuration changes over time
- Automated testing: Run linters/validators on configs
- Change notifications: Alert on specific changes
- Documentation: Auto-generate network documentation
Example GitHub Action (.github/workflows/audit.yml):
name: Config Audit
on: [push]
jobs:
audit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Check for sensitive data
run: |
# Check for potential secrets
grep -r "password\|secret\|key" . || echo "No secrets found"