OPNsense Forum

English Forums => Tutorials and FAQs => Topic started by: arrowd on November 30, 2026, 01:26:48 AM

Title: Setup guide for os-sftp-backup to a TrueNAS server
Post by: arrowd on November 30, 2026, 01:26:48 AM
Setup Guide for Automatic Backups of
OPNsense configuration to a TrueNAS server

There are different ways of setting up the process, some possibly more efficient than this, but these settings worked for me after a lot of false starts and web searching. I've generated this to both help future me and possibly help other non-experts interested in doing automatic backups. Improvements welcome.

1.   Enable SSH in OPNsense. At the web page go to System – Settings – Administration. In Secure Shell enable Secure Shell; Permit root user login; Permit password login; Port 22; Listen on your LAN (and perhaps VPN) interfaces.

2.   Use PuTTY or some other terminal program to connect by 'ssh root@<opnsense_IP> using the root password. Later on you can setup login by using SSH key pairs.

3.   Make a key pair to authenticate the SSH backup session. At the shell prompt enter
'ssh-keygen -t ed25519 -C "your_email@example.com" -f id_ed25519'. This will result in 'id_ed25519' and 'id_ed25519.pub' files in your /root directory. The email address after the -C is just a comment to label the keys and is not used for actual emails.

4.   If there is no .ssh directory in /root, 'mkdir .ssh' to add it. Set directory permissions to 'chmod 700. Move the two key files into /root/.ssh, and set their permissions with 'chmod 600'.

5.   Enable SSH on your TrueNAS server. At the web page go to System – Services – SSH; enable it to start automatically; no further editing is required.

6.   Use PuTTY or some other terminal program to connect by 'ssh root@<truenas_IP> using the root password.

7.   Create a home directory for the new user on your TrueNAS unit. Enter 'mkdir /mnt/<your pool name>/opnsense'.

8.   Enter 'cd /mnt/<your pool name>/opnsense'. If there is no .ssh directory there, 'mkdir .ssh' to add it. Set directory permissions with 'chmod 700. If not present, create an '.authorized_keys' file, and set the permissions with 'chmod 600'. Edit the file and append the contents of id_ed25519 to it.

9.   Enter 'mkdir Backups', and set permissions with 'chmod 600'.

10.   Configure a user on TrueNAS. Go to Credentials – Users. Click Add. For Username, enter opnsense; Allow Access for SMB and SSH. In 'Public SSH Key' field, paste in the contents of the id_ed25519.pub file. In Home Directory under Additional Details, set it to '/mnt/<your pool name>/opnsense'.

11.   Install the os-sftp-backup plugin on OPNsense at System – Firmware – Plugins.

12.   Configure the plugin at System – Configuration – Backups. Under sftp, Enable it; set the URL to 'sftp://opnsense@<your_truenas_IP>/Backups'. (Yes, there is a double slash.) For SSH private key, 'Click to edit' and paste in the contents of id_ed25519. Set the Backup Count to how many you want to keep. If you want to encrypt your backups, enter a password and confirm it. Click 'Setup/Test sftp'.

13.   If everything worked, you should see a message at the top of the screen that says 'Backup successful, current file list:' followed by a list of XML file names with the Unix times they were made as part of the names.

14.   If you get an error message instead, try this: get to a shell prompt on OPNsense and enter 'sftp opnsense@<your_truenas_IP>'. If successful, this started sftp in interactive mode – see the FreeBSD man page on sftp to see allowed commands. If instead, you get an error message from this sftp command, you can see expanded errors to diagnose the problem by entering 'sftp -v opnsense@<your_truenas_IP>'.

15.   Each time you manually run the Setup/Test, you will get another backup. When enabled, the process will run as a cron job at a random time between 1 and 2 AM every night. You can verify this by entering 'crontab -l' at a shell prompt, and finding the line that includes 'remote backups'. If your configuration hasn't changed, a new backup won't be transferred to TrueNAS.

16.   Backup events are recorded in System - Log Files – General.

17.   If you need to restore a previous configuration, copy the saved file to your workstation. In OPNsense go to System – Configuration – Backups. In the Restore section, Choose the file you just downloaded, and click 'Restore configuration'. If you encrypted the backup, click 'Configuration is encrypted' and enter the password in the field provided.

Title: Re: Setup guide for os-sftp-backup to a TrueNAS server
Post by: AzharAbbasPK on November 30, 2026, 05:00:48 AM
Nice guide, thanks for writing it up. Two small things though: in step 8 you should append the public key (id_ed25519.pub) to authorized_keys, not the private one, and step 9 should be chmod 700 for the Backups folder since a directory needs the execute bit to be entered.