Why does OpenSSH's sshd refuse a ChrootDirectory that the SFTP partner owns or that is group-writable, and how must the directory tree be laid out instead?
answer
- checked at session startup
- every component of the path
- who can rename a directory
- write one level down
basics
~20 ssshd chroots as root on the user's behalf, so it requires every directory on the chroot path to be root-owned and not group- or world-writable; otherwise the user could reshape their own jail. Writable folders go one level below.
solid answer
~50 s`chroot(2)` is a privileged call that sshd makes for the user at session startup. If the user, or anyone in a writable group, could modify a directory on that path, they could rename a component and put another directory or a symlink in its place, steering which tree becomes their root, or create files at the jail's top that programs trust by absolute path. So sshd checks that **every component** of the `ChrootDirectory` path, from `/` down, is root-owned and not writable by group or others, and refuses the session otherwise. The client just sees the connection close after authentication; the server log reports bad ownership or modes. The fix is a root-owned, 755 jail with a partner-owned `upload` folder inside it, and any processing job gets group access on that subfolder, never on the jail path.
go deeper
Remember the rule: every directory on the chroot path is owned by root and not writable by group or others, and the partner writes into a subfolder.
Explain the symptom (connection closes after authentication) and the log message, and lay out the three-level directory tree with owners and modes.
Explain why the rule exists: the chroot call is privileged, so anyone who can rename or create entries on the path can redirect or forge the jail. Show where a processing job's access goes instead.
Use the rule to shape the storage design: jails on a root-controlled tree, partner and pipeline access only below them, so operational convenience never requires loosening the path.
## The symptom A new partner account authenticates successfully and is disconnected at once. The `sftp` client reports that the connection closed; it never shows a prompt. On the server, sshd's log says the chroot directory has **bad ownership or modes**. Nothing is wrong with the key or with the account's `~/.ssh` permissions (that is a different check, made during public-key authentication). This check happens later, at **session startup**, when sshd is about to enter the jail. ## What sshd checks The `ChrootDirectory` documentation states the rule directly: at session startup sshd checks that **all components of the pathname are root-owned directories which are not writable by group or others**. For `ChrootDirectory /srv/drop/carrier07` that means: 1. `/` — root-owned, not group- or world-writable. 2. `/srv` — the same. 3. `/srv/drop` — the same. 4. `/srv/drop/carrier07` — the same, even though it is the partner's "home". A single component that belongs to an application account, or that carries group write for a team, fails the whole check. sshd applies it to every chroot, whether the session will run a shell or only the in-process `internal-sftp` server. ## Why the rule exists `chroot(2)` can only be called by root. sshd makes that call on the user's behalf, and whatever directory the path resolves to at that moment becomes the user's `/`. Two things go wrong if the user can write somewhere on that path: - **The path can be redirected.** Whoever can write to a directory can rename the entries in it. A user with write access to `/srv/drop` could move `carrier07` aside and put a symlink or a directory of their choosing in its place, so the privileged chroot lands somewhere the administrator never intended. - **The jail's contents can be forged.** Programs look up configuration by absolute path, and inside a jail those paths resolve within it. A user who can create files at the jail's top can supply their own versions of what a privileged program would read there. That is the classic way out of a writable chroot on a shell host. The manual adds the general principle: the directory hierarchy must be **prevented from modification by other processes on the system**, especially those outside the jail. Root ownership with no group or world write is the simplest state that guarantees only root decides what the jail is. ## The layout that works | Path | Owner | Mode | Purpose | |---|---|---|---| | `/srv/drop` | root | 755 | Parent of all jails | | `/srv/drop/carrier07` | root | 755 | The chroot; partner can list, not write | | `/srv/drop/carrier07/upload` | carrier07 | 750 or 770 | Where the partner writes | The partner logs in, lands at `/` (which is really `/srv/drop/carrier07`), and writes into `/upload`. Starting the session there with `internal-sftp -d /upload` saves the partner from a confusing "permission denied" at the top. ## Sharing files with a processing job The usual reason someone makes the jail group-writable is a downstream job that has to pick up or remove uploads. Give that access **below** the chroot instead: - put the processing account in a group that owns or can write the `upload` folder (the check covers only the components of the chroot path, not what is inside it); - or have a privileged mover on the host relocate files from `upload` into an internal area that the partner never sees. Either way the components of the jail path stay root-owned. ## Common mistakes - `chown carrier07 /srv/drop/carrier07` "so they can upload" — the session now closes immediately. - `chmod 775 /srv/drop` so a team can manage folders — every jail beneath it fails at once. - Turning off `StrictModes` to make it pass — that option governs checks on the user's home and key files; it does not relax the chroot ownership check. - Copying a shell and libraries into the jail — irrelevant here: the in-process `internal-sftp` server needs nothing inside the chroot, and the failure is about ownership, not missing files. ## Where this stops What each SFTP request can do once inside the jail is the request-level material's subject, and the `~/.ssh` permission rules that public-key login enforces belong to the material on operating OpenSSH on one host. This rule is only about the path sshd turns into the partner's root.
- A downstream job must delete processed files from each partner's drop. Where should its write access go?On the partner-owned `upload` subfolder, for example through a group that both the partner and the job belong to. The ownership check covers only the directories that make up the chroot path, so access inside the jail is free to design; the jail and its parents stay root-owned.
- Why can the partner still list the top of their jail but not create a file there?The chroot is root-owned with mode 755: read and execute for others lets the partner list it and enter subfolders, but without write permission they cannot create, rename or delete entries at the top. That is exactly the property the check enforces.
- The fix for a chroot error is to chown the home directory to the partner.
- Only the last directory of the chroot path is checked, not its parents.
- Setting StrictModes no switches off the chroot ownership check.
- The session fails because the chroot lacks a shell and libraries.
- Group write on the jail is safe as long as only trusted staff are in the group.