Isolate a backup upload account with SFTP chroot and boundary tests

Isolate a backup upload account with SFTP chroot and boundary tests

If a backup source machine is compromised, the upload key stored on it may also be stolen. If that key also permits command execution or access to the receiving server’s configuration, the backup connection becomes a route for lateral movement into the target machine. The receiver should separate permission to deliver files from permission to administer the system, then use negative tests to verify that the boundary holds.

This guide sets up a dedicated SFTP receiving account on Debian 12 without changing the disk layout or touching existing backup files. Qsfp dedicated servers use directly attached disks without hardware RAID; account isolation can narrow the scope of access, but it cannot replace disk redundancy or off-site copies.

1. Define the receiving boundary and acceptance criteria

The receiving account must accept public-key authentication only. After login, it must start in /incoming inside an isolated directory, with no interactive shell or SSH forwarding. Administrators continue to maintain the system through their existing accounts; the receiving account must not double as an account for routine administration.

SFTP is used here because the task requires file uploads only. If your backup software depends on executing remote commands or starting rsync over SSH, this setup will deliberately block those operations and cannot be applied as-is.

Before starting, keep a verified, working administrator session open and use a separate terminal for testing. After payment, check the connection address and credentials in the console; for a machine with multiple addresses, connect using the first address. Run the commands in this guide after obtaining root privileges through the administrator account. On the client, use a key generated specifically for uploads.

chroot restricts which paths an account can see; it does not provide immutable backups. A directory writable by the upload account will generally also allow that account to overwrite, rename, or delete files.

Acceptance testing must cover successful uploads, failed writes to the isolation root, host files remaining invisible, failed command execution, and rejected forwarding requests. A successful login alone is not enough.

2. Create the account and separate the writable directory

The following steps use a new account named backupdrop. First confirm that the name and paths are not already in use. Do not repurpose an existing application account as the receiving account. Install any missing components, then create the directories:

apt-get update
apt-get install openssh-server
adduser --disabled-password --gecos "" --no-create-home \
  --home /incoming --shell /usr/sbin/nologin backupdrop

install -d -o root -g root -m 0755 /srv/sftp
install -d -o root -g root -m 0755 /srv/sftp/backupdrop
install -d -o backupdrop -g backupdrop -m 0700 \
  /srv/sftp/backupdrop/incoming
install -d -o root -g root -m 0755 /etc/ssh/authorized_keys
namei -l /srv/sftp/backupdrop/incoming

/srv/sftp/backupdrop is the isolation root. It must be owned by root and must not be writable by the group or other users. Its parent directories must also meet these requirements. Upload write access belongs only on incoming; do not resolve errors by making the isolation root writable.

Generate a dedicated key on the sending machine and keep the private key there. How automated jobs unlock the private key should be covered by your existing credential-management process. Transfer the public key through a verified administrator channel and save it as /etc/ssh/authorized_keys/backupdrop, then set its ownership and permissions:

chown root:root /etc/ssh/authorized_keys/backupdrop
chmod 0644 /etc/ssh/authorized_keys/backupdrop

The public-key file resides outside the isolated directory and is maintained by an administrator, preventing the upload account from adding its own authorized keys. Use a different key for each sending machine so that each can be revoked independently. Never include private keys in support tickets or test records.

3. Restrict SFTP and verify the effective configuration

Back up the SSH configuration first. Confirm that the main configuration includes /etc/ssh/sshd_config.d/*.conf and that this Include appears in the global configuration context, then create a dedicated snippet. If Match rules already exist for this account, consolidate them first; do not infer precedence from filenames.

Match User backupdrop
    ChrootDirectory /srv/sftp/%u
    ForceCommand internal-sftp -d /incoming -u 0077
    AuthorizedKeysFile /etc/ssh/authorized_keys/%u
    AuthenticationMethods publickey
    PasswordAuthentication no
    KbdInteractiveAuthentication no
    DisableForwarding yes
    PermitTTY no
Match all

Save this as /etc/ssh/sshd_config.d/60-backupdrop.conf. With internal-sftp, there is no need to copy interpreters or shared libraries into the isolated directory. The 0077 mask restricts permissions on newly created files, but does not automatically correct permissions on existing files.

Check the syntax first, then inspect the effective configuration for this account:

/usr/sbin/sshd -t
/usr/sbin/sshd -T \
  -C user=backupdrop,host=localhost,addr=127.0.0.1 |
  grep -E '^(chrootdirectory|forcecommand|authorizedkeysfile|authenticationmethods|passwordauthentication|kbdinteractiveauthentication|disableforwarding|permittty) '

If there are also rules that match source addresses, replace the test address with the actual sender’s address and check again. Once the results match your expectations, run systemctl reload ssh and leave the original administrator session open.

Typical Debian 12 configurations use PAM. Account locking, expiration, or local policies may still prevent public-key login. If authentication fails, check the logs and account status first; do not enable password authentication just to get a connection working.

4. Test normal uploads and attempts to cross the boundary

On the client, define the alias backup-inbox in your existing SSH configuration. Explicitly specify the actual address, user backupdrop, dedicated private key, and actual connection parameters. Verify the host key through a trusted channel; do not disable host identity checking.

printf 'sftp acceptance\n' > /tmp/sftp-probe.txt
sftp backup-inbox

Once connected to SFTP, run these commands one at a time:

pwd
put /tmp/sftp-probe.txt probe.txt
ls -l probe.txt
cd /
mkdir forbidden
ls /etc
cd ..
pwd

The initial directory should be /incoming, and the upload should succeed. After switching to /, creating a directory should fail. In the isolation root newly created for this example, /etc does not exist. Even repeated cd .. commands must stop at the isolation root, without reaching paths on the host.

Next, exit SFTP and test remote commands and forwarding:

ssh -T backup-inbox id
ssh -N -o ExitOnForwardFailure=yes \
  -R 127.0.0.1:18080:127.0.0.1:18081 backup-inbox

The first command must not return identity information. The second should fail because forwarding is prohibited. These ports are used only for a controlled test; they are not default service ports. If a test unexpectedly hangs, terminate it and inspect the effective configuration. Do not treat a timeout as evidence that the request was rejected.

5. Complete the file lifecycle and provide a safe rollback

A successful upload does not mean a backup can be restored. The receiving workflow should use a temporary filename during transfer and rename the file only after the transfer completes. An independent verification job should check its size and digest. Once those checks pass, another identity should move the file to a location that the upload account cannot write to. The digest must come from a trusted source; otherwise, an attacker may replace both the file and its digest.

Also limit the capacity of the receiving area to prevent continuous uploads with a valid key from filling the disk. Test capacity limits and file-retention policies separately; directory isolation is not a storage quota. Full backup acceptance testing still requires actually reading and restoring the files in an isolated location.

If the change causes problems, use the retained administrator session to remove the new snippet or restore the original configuration, then run sshd -t. Once the check passes, reload the service and verify that a new administrator connection works. Do not restart the service and hope for the best, and do not delete the account or directories before moving the files to another location.

Finally, record a copy of the configuration, the public-key fingerprint, the results of both positive and negative tests, and the log locations. If login fails, check journalctl -u ssh and, where necessary, the system authentication logs to determine whether the issue is the key, directory permissions, or account policy. The receiving boundary is accepted only when both successful uploads and rejected boundary-crossing attempts produce repeatable results.

Frequently asked questions

Does SFTP chroot stop an upload account from deleting backups?

No. Write access to the inbox generally permits overwriting or deleting its files. A separate identity should move validated files to a location the uploader cannot modify, and an additional backup copy is still required.

Why must the upload account not own the chroot root?

OpenSSH requires the chroot path and its parent directories to be owned by root and not writable by the group or other users. Grant the upload account write access only to the incoming subdirectory.

Qsfp AMD EPYC 7543P dedicated server from $470.9/month

Use these requirements to configure a server

Review memory, storage, bandwidth, IPs, and OS, then confirm the dedicated server configuration.