All new Registrations are manually reviewed and approved, so a short delay after registration may occur before your account becomes active.
Need feedback: borgbackup server setup
Hi,
I am setting up a BorgBackup server using a storage VPS from HostHatch for the first time, primarily following the Gemini. So far, the setup is functioning as expected. I would appreciate any advice, especially regarding security best practices, to further secure the server and address any potential vulnerabilities I may have overlooked. Thank you.
Setup
1. Identify and Partition the New Disk
First, you need to identify the unpartitioned disk.
List block devices:
sudo lsblk -fLook for a disk that doesn't have any partitions listed under it or has unallocated space. It will likely be named something like
/dev/sdb,/dev/vdb, etc. Let's assume it's/dev/vdbfor this guide. Be absolutely sure you've identified the correct disk.Partition the disk using
fdisksudo su fdisk /dev/vdbInside
fdisk:
n- Create a new partition.p- Choose primary partition.1- Partition number.- Press Enter twice to accept default first and last sectors (uses the whole disk).
w- Write changes to disk and exit.
Verify the new partition:
lsblk -fYou should now see a new partition like
/dev/vdb1.
2. Format the New Partition
Now, format the newly created partition with a suitable filesystem like ext4.
sudo su
mkfs.ext4 -L YOURLABEL /dev/vdb1
3. Create a Mount Point and Mount the Partition
Create a directory to mount the partition: This will be the root of your Borg backup storage.
sudo su mkdir /mnt/borg-storageMount the partition:
sudo mount /dev/vdb1 /mnt/borg-storageMake the mount permanent (fstab):
First, get the UUID of the new partition:
sudo blkid /dev/vdb1Copy the
UUIDvalue (e.g.,
UUID="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx").
Open
/etc/fstabAdd a line like this at the end, replacing
YOUR_UUID_HEREwith the actual UUID you copied and
/mnt/borg-storagewith your chosen mount point:
UUID=YOUR_UUID_HERE /mnt/borg-storage ext4 defaults 0 2or you can use LABEL
LABEL=YOURLABEL /mnt/borg-storage ext4 defaults 0 2Save and close the file.
Verify it's mounted:
df -h /mnt/borg-storage
4. Install BorgBackup
Install BorgBackup on the server:
5. Create User Accounts and Home Directories for Borg
You'll create dedicated user accounts (can add more user later). These users will only have access to their specific Borg repositories.
Create a group for Borg users (optional, but good practice):
sudo groupadd borgusersCreate users and their dedicated Borg repository directories: Repeat for each user (user1, user2, ..., user5).
# For user1 sudo useradd -m -d /mnt/borg-storage/user1 -s /bin/bash -g borgusers user1 sudo chown -R user1:borgusers /mnt/borg-storage/user1 sudo chmod -R 700 /mnt/borg-storage/user1 # ... and so on for other users
-m: Create home directory.-d /mnt/borg-storage/userX: Sets their home directory to be within your backup storage. This is where their Borg repo will live.-s /bin/bash: You can set this to/usr/sbin/nologinor a restricted shell later if you want to prevent interactive logins, but for Borg, they need to execute theborg servecommand. We'll restrict commands viaauthorized_keys.-g borgusers: Adds the user to theborgusersgroup.
6. Configure SSH and authorized_keys for Restricted Borg Access
This is crucial for security. Each user will provide their public SSH key. You'll add it to their respective ~/.ssh/authorized_keys file on the server with a command restriction, allowing only Borg operations.
- For each user (e.g.,
user1):
Ensure the
.sshdirectory exists and has correct permissions (do this as the user, or as root thenchown).# As root, preparing for user1 sudo mkdir -p /mnt/borg-storage/user1/.ssh sudo touch /mnt/borg-storage/user1/.ssh/authorized_keys sudo chown -R user1:borgusers /mnt/borg-storage/user1/.ssh sudo chmod 700 /mnt/borg-storage/user1/.ssh sudo chmod 600 /mnt/borg-storage/user1/.ssh/authorized_keysGet the public SSH key from
user1(e.g.,id_rsa.puborid_ed25519.pubfrom their client machine).Edit
user1'sauthorized_keysfile:sudo nano /mnt/borg-storage/user1/.ssh/authorized_keysAdd the public key, prepended with the
commandrestriction. The path to the repository should be the absolute path on the server that this user is allowed to access. For Ed25519 keys:command="cd /mnt/borg-storage/user1; borg serve --storage-quota 20G --restrict-to-path /mnt/borg-storage/user1",restrict ssh-ed25519 AAA... user1@clientmachineExplanation:
command="borg serve --restrict-to-path /mnt/borg-storage/user1": This forces any SSH connection using this key to only execute theborg servecommand and only allows it to operate on the specified path.restrict: Adds further restrictions (disables port forwarding, X11 forwarding, etc.).ssh-ed25519 AAA...: This is the actual public key content.
7. Initialize Repositories (Client-Side)
Each user will need to initialize their Borg repository from their client machine once.
On user1's client machine:
# Replace server_ip_or_hostname with your server's address
export BORG_REPO='ssh://user1@server_ip_or_hostname/./REPOSITORY_NAME'
# Recommended: Use repokey encryption for security
borg init --encryption=repokey-blake2

Comments
there's extensive documentation around borg and borgmatic. I'd suggest reading that instead of asking AI tools and hoping for the rest to come from people on here. it's worthwhile to have an understanding
I do understand the risks, AI isn't the sole resources to setup. As of now the setup is working as expected.