You set up a dedicated backup user. You configure SSH keys. You set up sudo rules for the specific commands you need. Then you run the backup and — permission denied on the SSH key file.
The key's mode is 600. The backup user can't read it. You could chmod 640 and add the user to the key owner's group, but then new keys won't inherit the ACL. You could run the backup as root, but that defeats the whole point of a dedicated user.
This is the backup permission dilemma. Here's how I've worked around it.
The core problem
SSH is strict about key permissions. ~/.ssh/id_ed25519 must be 600 (or 400). The backup user needs to read it. But the key belongs to the service account (or root), and SSH will refuse to use a key that's group- or world-readable.
ACLs seem like the answer:
setfacl -m u:backup:r /home/service/.ssh/id_ed25519
setfacl -d -m u:backup:r /home/service/.ssh/
The default ACL handles new files. But SSH still complains because the effective permissions (as shown by ls -l) show group/other bits that SSH considers too open. SSH checks the mode bits, not ACLs.
Option 1: sudo with a restricted command
Give the backup user a specific sudo rule:
# /etc/sudoers.d/backup
backup ALL=(service) NOPASSWD: /usr/bin/rsync
Then the backup script runs:
sudo -u service rsync -avz --rsync-path="sudo rsync" source/ dest/
The backup user never touches the key. The service account runs rsync with its own key. Clean separation.
Option 2: dedicated key for backup
Generate a separate key for the backup user:
sudo -u backup ssh-keygen -t ed25519 -f /home/backup/.ssh/backup_key -N ""
Add the public key to the remote server's authorized_keys with a command= restriction and from= limit if possible:
command="/usr/bin/rsync --server --sender -vlogDtprze.iLsfxC . /source/",from="10.0.0.5" ssh-ed25519 AAAA... backup@host
The backup user owns its key (600, no ACL needed). The remote side restricts what that key can do. If the backup host is compromised, the attacker gets rsync read access to one path — not a shell.
Option 3: ssh-agent forwarding (with caveats)
Run the backup from your workstation, forward your agent:
ssh -A backup@backup-host 'rsync -avz -e "ssh -A" source/ dest/'
Your key never lands on the backup host. But agent forwarding has its own risks — a compromised backup host can use your agent while the connection is open. Only viable if you trust the backup host more than the network path.
What I actually use
Option 2. A dedicated key per backup job, restricted on the remote side. The backup user owns its key (mode 600, no ACL fights). The remote authorized_keys limits the damage if that key leaks. The sudo rule (Option 1) is a solid fallback when you can't touch the remote authorized_keys.
The ACL approach looks like it should work. It doesn't, because SSH checks mode bits. Save yourself the debugging time.
Originally inspired by an Ask HN thread on backup user permissions. The ACL trap is real.
Top comments (0)