The last post was about a tool for locking and unlocking files using immutable and append-only flags; this one is about copying files from one place to another, between hosts or (sometimes) on the same host, as a building block for automations without creating unnecessary security exposures. Both of these components will be used in later tools.
rsync Basics rsync is a common tool used for efficiently copying files and directories from one location to another, including between systems and for backup purposes. I’ve used it for almost as long as I’ve been managing home systems. The base use case is to synchronize files owned by the same user, but for my main use cases, distributing administration-related configuration files and performing backups, more access is required. Since I don’t allow root logins, I need a non-privileged remote user with enough access to deploy files where they belong and to copy everything I want backed up. The most common way to restrict a non-privileged remote user to specific functions is to limit it to specific authorized commands that can be sent via SSH (secure shell), and to configure sudo or doas on the remote system for that non-privileged user to allow it to do what it needs to do, as specifically as possible. Specific commands are defined in the destination user’s .ssh/authorized_keys file. I used to use a very simple wrapper on the remote side that would only allow rsync to run, but came to the conclusion that I wanted stricter controls that limited what rsync could do. (An alternative tool for restricting remote SSH commands that I came across during research for this post is sshdo.) I set up a non-privileged user, _rsyncu, on each host where it’s needed and use separate SSH keys with specific commands for each specific function, and define privileged commands that it might need to execute, as narrowly as possible, using doas (I formerly used the more popular sudo but switched to doas when OpenBSD did; it is simpler and has had fewer vulnerabilities)
...