How to access a `borgmatic mount` as a normal user

I use Borgmatic for backups to a remote server using a systemd system unit (i.e. as root) so I can back up both /etc and /home/hook in one go.

But when I sudo borgmatic mount, I cannot read the mountpoint as a normal user due to permissions.

I tried, and failed, so far:

  • changing the permissions of the mountpoint
  • changing the permissions of /etc/borgmatic/* – won’t work, because borg(matic) for security reasons fails if the ssh key therein is shared with any other users
  • using sudo borgmatic mount --mount-point /mnt/backup_mnt/ --options uid=1000,gid=1000

Maybe this helps:

sudo chmod g+x /etc/borgmatic

It didn’t help.

Also I just realised that this approach won’t help me at all, since borg(matic) fails if the ssh key has lax permissions.

I’ll rephrase the original question to reflect the background problem then.

BTW what does command
id
show?

uid=1000(hook) gid=1000(hook) skupine=1000(hook),19(log),50(games),982(rfkill),984(users),998(wheel),1001(roccat),1002(backup)
1 Like

That borgmatic mount command has gid=1000, but should it be gid=1002?
(Note that I’m not using borgmatic, just guessing.)

1000 should still work, since I’m in both groups (and IMHO should work with just uid=1000 anyway).

It looks like you need to install it a different way to run borgmatic as a non-root user, or use sudo with it.

Root install

If you want to run borgmatic on a schedule with privileged access to your files, then you should install borgmatic as the root user by running the following commands:

sudo pipx ensurepath
sudo pipx install borgmatic

Check whether this worked with:

sudo su -
borgmatic --version

If borgmatic is properly installed, that should output your borgmatic version. And if you’d also like sudo borgmatic to work, keep reading!

Non-root install

If you only want to run borgmatic as a non-root user (without privileged file access) or you want to make sudo borgmatic work so borgmatic runs as root, then install borgmatic as a non-root user by running the following commands as that user:

pipx ensurepath
pipx install borgmatic

This should work even if you’ve also installed borgmatic as the root user.

Check whether this worked with:

borgmatic --version

If borgmatic is properly installed, that should output your borgmatic version. You can also try sudo borgmatic --version if you intend to run borgmatic with sudo. If that doesn’t work, you may need to update your sudoers secure_path option.