Overview
Making configuration changes or rule updates to OPNsense does not always go to plan (ask me how I know). I’ve found myself having to re-configure OPNsense based on fragments of my sieve-like memory on several occasions.
Sure, I may have had some older manual config backups to use as a baseline, but without a regular, consistent backup schedule, the risk of losing hours to setup and testing is very real.
Automating the backup of OPNsense can save plenty of time and mucking about in the event something goes “pear-shaped”.
This process utilises a downloadable plugin for OPNsense called os-git-backup. When using GitHub, the only available option is to use SSH for authentication as the use of HTTPS credentials is not longer accepted by GitHub.
- Note: Other options available for plugin-based backups include Google Drive and SFTP.
Additional Information
Requirements
- Outbound Internet access from OPNsense (required for updates and plug-in installation).
- A new empty GitHub repository with visibility set to private!
- This must be a brand new repository, with no existing files (README or LICENSE etc).
Enable SSH for OPNsense
Note: This section is only required if console access to the device is not available. Enabling SSH access to the OPNsense firewall will provide a means to generate the SSH key-pair. This change should only be used temporarily, and be reverted once this process has been completed.
- Navigate to the menu section
System > Settings > Administration. - Scroll down the page and locate the section
Secure Shell. - Enable the
Secure Shelltick box and optionally the root user account with password authentication.
Generate OPNsense SSH Key-Pair
- Login to the OPNsense device via SSH.
- Generate the SSH key-pair in the
.sshdirectory (created if missing). - The use of parameter
-n ""ensures that no passphrase is set (required by the plugin).
|
|
- Confirm that the two files are generated in the
/root/.sshdirectory.
|
|
- Copy the output of both the private and public key (
.pub) files for use with GitHub and OPNsense configuration.
|
|
GitHub SSH Setup
A new, blank repository is required for this setup. This means no existing files can be present at all. If you are yet to create a new repository, do this now. Make sure not to initialise the repo with a README or LICENSE file.
- From within GitHub, access the new repository.
- Navigate to the repository
Settingsand selectDeploy Keys. - Click
Add Deploy Key. - Add the SSH public key to the
keysection, enableAllow Write Access. - Click
Add Key.

OPNsense Backup Configuration
- From inside the OPNsense web GUI, navigate to the menu item
System > Firmware > Plugins. - Locate the plugin named
os-git-backupand click the+icon to install it.

- Once installed, navigate to
System > Configuration > Backups. - A new menu section named
Gitshould now be available. - Enable the
Gitbackup service.

- Add the SSH URL and primary branch for your new GitHub repo (
masterby default). - Add the private SSH key in the required field.
- For SSH connections to GitHub, the user should be set as
gitwith no password defined (using SSH keys). - Click
Setup/Test Gitto confirm. - The page should refresh followed with a top header message
Backup successful, current file list: config.xml. - The OPNsense
config.xmlfile should now be visible in the GitHub repository.

Cover photo by Jandira Sonnendeck on Unsplash