About this article: This article is reviewed against the cited sources. This is source research, not lab validation. Check the stated versions and your own requirements before making changes.
To let a sender deliver backup copies without giving it a shell or the rest of your server, create a dedicated account for that sender and confine it in OpenSSH. In practice that means six settings working together: a folder the account is locked into (ChrootDirectory), the built-in file-transfer server only (ForceCommand internal-sftp), public-key login only, all forwarding switched off, no terminal, and no user start-up script (PermitUserRC).
These settings limit what a logged-in account can reach. They do not make delivered files tamper-proof, and each has conditions that, if missed, quietly weaken it. This guide is for the IT administrator of a business that runs its own receiving server. It explains each control from the manuals, shows the limits, and ends with a checklist. It is general information, not a tested build.
Why it matters
A server that accepts backup copies from outside is a target. The sender's credentials may sit on a machine that is itself compromised. If that credential also gives a shell, or access to other folders, one stolen key becomes access to your server.
Three outcomes matter. The sender must be able to deliver. The sender must not reach anything else. And the delivered copies must survive a mistake or an attacker holding the sender's key. Configuration addresses the first two; the third needs a retention design, set out below.
SFTP here means the SSH File Transfer Protocol, carried inside an SSH connection and offered by the OpenSSH server (sshd) as a subsystem, a named helper program.
The building blocks, from the manuals
The manual wording below is from the OpenBSD copies of the OpenSSH manuals. Linux distributions ship OpenSSH Portable, and keywords and defaults can differ by version, so confirm each on your own server's manual page.
A dedicated account and a confined folder
ChrootDirectory sets "the pathname of a directory to chroot(2) to after authentication." A chroot makes the chosen folder appear as the whole filesystem. Two conditions from sshd_config(5) cause most failures and weaknesses:
- "sshd(8) checks that all components of the pathname are root-owned directories which are not writable by group or others." Every folder on the path to the chroot, not just the last, must be owned by root and not writable by the sender.
- The manual also warns that "Misconfiguration can lead to unsafe environments which sshd(8) cannot detect."
Because the chroot folder must be root-owned and not writable by the sender, the sender cannot create files directly in it. The usual pattern (our description) is a root-owned chroot folder with a sender-owned subfolder inside it, such as incoming, where files are written. internal-sftp -d sets the starting directory, described below.
The Linux manual page for chroot(2) is a caution: the call "is not intended to be used for any kind of security purpose, neither to fully sandbox a process nor to restrict filesystem system calls." (chroot(2).) In our reading, a chroot is one layer. Keep the account unprivileged and give it no shell.
The built-in file-transfer server, and no shell
The Subsystem keyword explains that "internal-sftp implements an in-process SFTP server" which "may simplify configurations using ChrootDirectory." The ForceCommand keyword goes further: "Specifying a command of internal-sftp will force the use of an in-process SFTP server that requires no support files when used with ChrootDirectory." So a confined SFTP account needs no shell program, devices or libraries inside the chroot, and cannot run commands: the forced command replaces whatever the client asks for.
Key-only login
PasswordAuthentication and KbdInteractiveAuthentication default to yes, so both must be switched off explicitly for this account. AuthenticationMethods "specifies the authentication methods that must be successfully completed for a user to be granted access." Setting it to publickey for the sender account means a stolen or guessed password gets nobody in.
You can tighten each key in its authorized_keys entry (documented in sshd(8)): from="pattern-list" requires the client's address or name to match, and the restrict option, in the manual's words, "Enable all restrictions, i.e. disable port, agent and X11 forwarding, as well as disabling PTY allocation and execution of ~/.ssh/rc". Our recommendation is to give each sender its own key and account, so one can be revoked without disturbing the others.
The user's rc script is a file that sshd may run when a user logs in. PermitUserRC "Specifies whether any ~/.ssh/rc file is executed", and "The default is yes". The fragment below therefore sets PermitUserRC no for this account, and every authorised key should also carry restrict, so a gap in one place is covered by the other. PermitUserRC is among the keywords the manual allows after Match. Our recommendation is to switch it off for this account whether or not an rc file would run in a chrooted internal-sftp session, rather than depend on the answer.
Forwarding and terminals off
Forced commands do not stop everything. The manual says ForceCommand "does not limit other kinds of access that a client may request via their connection, such as TCP, agent, socket or X11 forwarding." These "must be explicitly disabled, either individually via their respective options or all together using the DisableForwarding option." PermitTTY defaults to yes; set it to no for this account. The manual also cautions that disabling forwarding "does not improve security unless users are also denied shell access", which is why the forced command and a no-shell account come together.
Applying settings to one account only
The Match keyword "introduces a conditional block", and the keywords after it apply to that user only. All the keywords used here, including PermitUserRC, are allowed in a Match block. The manual notes "If a keyword appears in multiple Match blocks that are satisfied, only the first instance of the keyword is applied", which makes block order important. AllowUsers or AllowGroups can additionally limit who may log in at all.
An illustrative configuration fragment
The fragment below uses only keywords described above. It is illustrative, was not run or tested, and is for comparison with your own file, not pasting. Make changes in a test environment first, with a second administrative session open, so a mistake does not lock you out. The account name and paths are invented.
Match User backupsender
ChrootDirectory /srv/backup-drop/%u
ForceCommand internal-sftp -d /incoming -l INFO
AuthenticationMethods publickey
PasswordAuthentication no
KbdInteractiveAuthentication no
DisableForwarding yes
PermitTTY no
PermitUserRC no
%u is a token for the user name, accepted by ChrootDirectory. -d sets the start directory, which "is useful in conjunction with the sshd_config(5) ChrootDirectory option", and, in our understanding, inside a chroot the path is read from the new root. -l INFO sets the log level. The sftp-server(8) manual says "INFO and VERBOSE log transactions that sftp-server performs on behalf of the client" and that the default level is ERROR, so without -l those transactions are not logged. The sshd_config(5) manual says settings such as LogLevel do not apply to internal-sftp and "must be set explicitly via command line arguments", which is why the level is on the ForceCommand line. On some systems logging also needs a log socket inside the chroot (see sftp-server(8)).
Write access, not delete access
Write-only is harder than it sounds, and our reading is that it is often not what a backup sender needs.
sftp-server can refuse chosen request types. Its -P option "specifies a comma-separated list of SFTP protocol requests that are banned by the server", and -p lists the only ones allowed. The manual adds a warning: "Care must be taken when using this feature to ensure that requests made implicitly by SFTP clients are permitted." The -R option is a read-only mode, the opposite of what a receiving account needs.
The request names, such as remove, rmdir, rename and write, appear in the OpenSSH source for sftp-server (sftp-server.c), and the manual says the -Q flag can be used to determine the supported request types. Banning remove and rmdir stops an ordinary client from deleting delivered files. But backup tools often upload to a temporary name and rename it on completion, so banning rename may break deliveries. The source lists a separate posix-rename@openssh.com request alongside plain rename, so, in our reading, banning one does not ban the other. It also lists a symlink request and a hardlink@openssh.com extension; whether to deny them depends on whether your sender uses them, and the retention design below does not depend on the answer. Build any -P or -p list from the server's own sftp-server -Q requests output, and test with the real sender before relying on it.
Two limits follow, and they are our reading. First, a sender allowed to write can usually overwrite a file it can open, so banned deletion is not immutability. Second, on Linux the execute bit on a folder governs "search permission in case of directories" (path_resolution(7)), so a folder can allow entry without allowing a listing; whether that suits your sender depends on whether its software reads back what it has sent.
A stronger design treats the drop folder as a landing area only, as set out next.
Keeping a retained copy the sender cannot change
It is tempting to have a job move completed files into a folder the sender cannot reach. A rename within one filesystem, which is what rename(2) and link(2) describe, is not protection. The Linux manuals say why:
- open(2): a file descriptor "is a reference to an open file description; this reference is unaffected if path is subsequently removed or modified to refer to a different file." A sender that opened a file for writing before the move can, as far as these manuals show, keep writing to it.
- rename(2): "Any other hard links to the file (as created using link(2)) are unaffected. Open file descriptors for oldpath are also unaffected." A moved file is the same file under a new name.
- link(2): "both names refer to the same file (and so have the same permissions and ownership)". A second name the sender made inside its own folder still reaches the file after the first is moved.
Do not rely on a permission change after the move: it is not a safe way to cancel a handle that is already open. Our recommendation, which is a design only and untested, is to make an independent copy with its own permissions, a different file from anything the sender ever had a handle or a name for, and to take that copy only while the sender cannot connect or write.
Checking once that no session is open is not enough for that. A new connection can arrive a moment after the check, while the job is still validating and copying, and a pathname that was checked can be replaced by the time it is opened. The design below therefore has two parts: a capture window that is closed to the sender for its whole length, and identity checks made on the file that was actually opened.
- Close the capture window. Before the job reads anything, stop the sender account from starting new sessions. One way is to add the account to
DenyUsers, a keyword the sshd_config(5) manual lists as usable after Match, and have sshd re-read its configuration, which sshd(8) says it does on SIGHUP. Another is to disable the account in the operating system. A locked password alone is not enough for a key-only account: the usermod(8) manual describes-Las locking "a user's password" and says that to lock the account, "not only access with a password", the expiry date should also be set. Whichever you choose, deliveries are refused while the window is closed, so keep it short and make sure the sender's software retries. - Drain existing sessions. Closing the window stops new sessions only. The sshd(8) manual says sshd "forks a new daemon for each incoming connection", and the manuals we read do not say that a configuration reload ends sessions already open, so do not assume it does. Wait for the sender's sessions to finish, or end them with your operating system's process tools, and confirm that none remain. Because new sessions are already blocked, this check can no longer be overtaken by a new connection. Start capture only after it passes; if sessions will not end, reopen the window and try later.
- Consider only finished files. Take only files the sender's tool has finished writing, for example by its rename from a temporary name, and only with the window closed.
- Treat the landing area as untrusted, and check the file you opened. The job runs as a separate account, outside the chroot, so it sees real paths, not the sender's view. A symbolic link, per symlink(7), "is a pointer to another name, and not to an underlying object". Checking a pathname and then opening it leaves a gap in which the name could be replaced. Instead, open first and check the result: on Linux the openat2(2) system call (since Linux 5.6) can open a file relative to the landing folder with
RESOLVE_NO_SYMLINKS, which it describes as "Disallow resolution of symbolic links during path resolution", andRESOLVE_BENEATH, which refuses any path whose resolution leaves that folder. This is wider than the O_NOFOLLOW flag in open(2), which covers only the last part of a path: "Symbolic links in earlier components of the pathname will still be followed." Then run fstat(2) on the descriptor you hold, which is "identical to stat (), except that the file about which information is to be retrieved is specified by the file descriptor", and accept it only if it is an ordinary file with a link count of one, and in the size range you expect. Read the bytes from that same descriptor, not from the path again. Skip and report symbolic links, hard-linked files, directories and special files. open(2) says a descriptor "is a reference to an open file description; this reference is unaffected if path is subsequently removed or modified to refer to a different file", so what you read is the file you checked. - Validate the upload. Compare size and a checksum with a manifest or the sender tool's own verification. A truncated upload stays in the landing area and is reported.
- Copy, do not move. Write the bytes into a new file in the store, created so it must not already exist (open(2): O_EXCL "Ensure that this call creates the file"), owned by the job account, not writable by the sender account, in a folder the sender cannot enter. Use a unique name, such as date plus checksum, so a later upload cannot replace an earlier copy.
- Verify the copy. Read it back, compare its checksum with step 5, and record it in a log the sender cannot write.
- Clear only what was verified, then reopen the window. While the sender is still blocked, remove from the landing area only the exact files whose copies passed step 7: before removing each one, confirm that its name still refers to the same file you opened and checked in step 4 (the same device and inode numbers from fstat(2)), and leave it in place if it does not. Keep every file that failed validation, was skipped or was not verified, and report it. Then restore whichever admission control step 1 changed (remove the account from
DenyUsersand reload, or undo the account expiry or disabling) in every outcome, including when an earlier step failed, and alert if that restore fails or the window stays closed longer than planned, since a closed window looks to the sender like a failed destination. Never clear the landing area by pathname after the window has reopened, because by then a new upload can reuse a name. - Protect the store separately. Keep versions or snapshots under a different administrator account, and consider an offsite copy. Some Linux filesystems can mark files immutable or append-only (link(2) mentions both); test whether that suits you.
Then test rather than claim. In a test environment, with a test sender account, never on a live server:
- With the window closed, try to connect as the sender and confirm the connection is refused; start a session before closing the window and confirm the job waits or stops rather than capturing.
- Hold a file open for writing in a session that began before the window closed, run the job, write more through the open handle, and see whether the retained copy changed. The job should have skipped it.
- Create a symbolic link and a second name for a file (if your server allows those requests), and see that the job refuses both. Swap a name for a symbolic link between listing and opening, and see that the open fails.
- Interrupt an upload, upload twice with the same name, and fill the landing disk.
- Restore from a retained copy and compare checksums.
Record what you saw. Until then, call the store designed to be independent, not immutable.
Disk space and monitoring
Nothing in the SSH manuals limits how much a sender may write, so a runaway job or a stolen key could fill the disk. Our recommendation, which these sources do not cover, is to place the drop area on its own filesystem or volume, apply your operating system's quota facility, and alert on free space and on deliveries that stop. A destination that quietly stops receiving is a backup failure.
Read-only checks
The commands below read configuration and permissions and change nothing. They were not tested for this article; the options are from the manuals cited. Run them on your own server with an administrator account.
Linux shell: print the effective settings sshd would apply to a connection from the sender account. The -T option performs what the manual calls "Extended test mode": "Check the validity of the configuration file, output the effective configuration to stdout and then exit." The -C supplies connection details so Match blocks apply (sshd(8)). Use your own account name, host name and address.
sudo sshd -T -C user=backupsender,host=sender.example.com,addr=192.0.2.10
In the output, look for the chroot directory, the forced command, the authentication methods, the forwarding and terminal settings, and the PermitUserRC setting. Then open the sender's authorized_keys file (it holds public keys only) and confirm each key line carries restrict.
Linux shell: list the ownership and permissions of every folder on the chroot path, and the folder inside it. The -d option will "list directories themselves, not their contents" (ls(1), Linux man-pages). Use your own paths.
ls -ld /srv /srv/backup-drop /srv/backup-drop/backupsender /srv/backup-drop/backupsender/incoming
Every folder on the chroot path should be owned by root and not writable by group or others, except the inner folder you intend the sender to write to.
Linux shell: show the fingerprint of a sender's public key, to match against the key the sender says it holds (ssh-keygen(1): "show fingerprint of specified public key file").
ssh-keygen -l -f /path/to/sender-key.pub
Checklist
Compare your current configuration with this list (our synthesis of the points above).
- One account per sender, with no shell and no other duties.
- A root-owned chroot path, not writable by group or others, at every level.
- A sender-writable folder inside the chroot, and nothing else writable.
- ForceCommand internal-sftp, with a start directory set.
- Public-key authentication only; passwords and keyboard-interactive off.
- Each key restricted by address where the sender's address is stable, and carrying
restrict. - All forwarding and terminal allocation disabled for the account, and PermitUserRC set to no.
- Settings applied through a Match block that is checked with the extended test mode.
- Logging enabled for the SFTP server, and logs reviewed.
- Retained copies made by copying, not moving, into a store under separate permissions with snapshots, taken only while the sender cannot connect, with existing sessions drained and each file checked on the descriptor opened, and the tests above recorded.
- Disk limits and alerts for the landing area.
A worked example (illustrative)
The following is invented. A small firm sets up a receiving server and tests the first draft with its sender. The upload works, but the sender account can still ask for a terminal because only the chroot was set. The administrator adds the forced command, turns off passwords and forwarding, sets PermitUserRC to no, adds restrict to the key, and runs the extended test to confirm the effective settings.
Next, a test delivery fails because the sender's software renames its temporary file after upload, which the administrator had banned. The administrator allows rename. The first plan is a nightly job that moves completed files to a folder the sender cannot reach. On rereading open(2), rename(2) and link(2), the administrator sees that a move leaves the same file in place, so a handle the sender holds open, or a second name it creates, could still reach it. The plan changes to the retention steps above.
The administrator also notes that a plan to run the job after one check that no session is open would still let a new connection start mid-copy, so the design blocks the sender account for the capture window, drains sessions, and checks each file on the descriptor opened. The administrator then runs the window, handle, symbolic link, hard link, interrupted upload and restore tests in a test environment, and leaves the retention items on the checklist unticked until the results are recorded. The sender's ability to overwrite files in the landing area is accepted, because the files relied on are independent copies.
Read next
Related articles you may want next.
- Backup & RecoveryImmutable Backup Repositories on Linux: Hardened Design, Attributes, Credentials and LimitsWhat the Linux immutable attribute enforces, who can still remove it, and how to design credentials, retention and clocks so backups cannot be erased.Read article
- Backup & RecoveryBacking up Linux files to S3 object storage: what survives and what is lostWhat an S3 copy of Linux files keeps and loses: owners, permissions, timestamps, links, empty folders and checksums, from AWS and rclone documentation.Read article
- Backup & RecoveryVerify a Backup Delivered to S3 or SFTP Before RecoveryCheck delivered backup identity, completeness and integrity, then rehearse extraction and recovery using independently available credentials.Read article
Risks and limits
- The sources are the OpenBSD manual pages. Portable OpenSSH on Linux may differ in version and defaults; check yours.
- The fragment, checklist and retention steps are a design only: illustrative, untested and not run on any live server. Blocking the sender for a capture window means deliveries are refused for that time; the design does not remove that cost.
- The linux-specific calls named (openat2, fstat) apply to a job written for Linux; their behaviour on other systems or on network filesystems was not examined. A qualified administrator should review and test them against your server and sender.
- A confined account is not an immutable archive, and we do not claim a retained copy is immutable. Filesystem behaviour differs between systems and mount options.
- A copy preserves what arrived, including false or empty uploads from a stolen key.
- Retention, quota and monitoring advice is our recommendation; the manuals cited do not cover quotas.
- Host keys, firewalling and operating system patching are outside this guide.
Next step
Print your server's effective settings for the sender account, compare them with the checklist, and fix the first gap in a test environment. If you are reviewing a backup service that delivers to your server, the Backup and Recovery page is a starting point for that conversation; ask for the scope in writing.
Sources
- sshd_config(5), OpenBSD manual pages (OpenSSH), dated 30 October 2026.
- sftp-server(8), OpenBSD manual pages (OpenSSH), dated 25 August 2026.
- sshd(8), OpenBSD manual pages (OpenSSH), dated 2 September 2026.
- ssh-keygen(1), OpenBSD manual pages (OpenSSH), date unavailable.
- ls(1), Linux man-pages (man7.org), date unavailable.
- sftp-server.c, OpenSSH Portable source, master branch, date unavailable.
- chroot(2), Linux man-pages 6.19, 2026-02-08.
- path_resolution(7), Linux man-pages, date unavailable.
- open(2), Linux man-pages 6.19, 2026-02-08.
- rename(2), Linux man-pages 6.19, 2026-02-08.
- link(2), Linux man-pages 6.19, 2026-02-11.
- symlink(7), Linux man-pages, date unavailable.
- openat2(2), Linux man-pages 6.19, 2026-07-02.
- fstat(2) (stat(2)), Linux man-pages 6.19, 2026-02-08.
- usermod(8), Linux man-pages (shadow-utils), date unavailable.
First accessed 15 November 2026, except open(2), rename(2), link(2), symlink(7), openat2(2), fstat(2) and usermod(8), first accessed 16 November 2026; the OpenSSH manuals and source were re-read 16 November 2026.
Learning notes
- Confining an account to a folder is a layer, not a guarantee; it works only if the folder path is owned by root and not writable by others.
- A forced internal-sftp command removes the shell, but forwarding and terminals must be switched off separately.
- Key-only login means switching passwords off, since they are on by default.
- Set PermitUserRC to no for the sender account and put
restricton every key. - Moving a file is not protecting it: an open handle or a second name can still reach a moved file. Keep an independent copy, and test it before you call it safe.
- Checking once that no session is open is not a safe basis for capture, because a new connection can arrive during the copy. Block new sender sessions for the whole window, drain existing ones, then open each file and check the descriptor you hold.
This article was originally published on .