skip to content

How do you get per-file transfer logs and request limits from OpenSSH's internal-sftp for chrooted partners, and why doesn't sshd's LogLevel produce them?

level: seniorimportance: nice to knowfreq 12%

answer

  1. the server logs for itself
  2. flags on the ForceCommand line
  3. a socket inside the jail
  4. deny before allow
  5. order mattered before 10.4

basics

~20 s

Give internal-sftp its own flags: -l INFO (or VERBOSE) and -f for the facility, because sshd's LogLevel and SyslogFacility do not apply to it; -P and -p deny or allow requests. Some systems also need /dev/log inside the chroot.

solid answer

~50 s

`internal-sftp` accepts the same options as `sftp-server`, and the manual is explicit that sshd's `LogLevel` and `SyslogFacility` do **not** apply to it. Its own default is `-l ERROR` with facility `AUTH`, which logs no transfers. `ForceCommand internal-sftp -l INFO -f LOCAL5` logs session open and close with the client address, every `open` and `close` with bytes read and written, renames, removals and directory changes; `-l VERBOSE` adds refused requests. `-P` takes a comma-separated deny list of request names and `-p` an allow list (deny is applied first); `-R` makes the session read-only. On some systems logging from inside a chroot needs a `/dev/log` socket created in each jail by the syslog daemon. Before OpenSSH 10.4, internal-sftp silently dropped arguments after the ninth, so a deny list at the end of a long line could vanish.

go deeper

for a junior

Remember that transfer logs come from the SFTP server, not from sshd's login logging, and that internal-sftp takes its own -l and -f flags.

for a middle

Explain the -l, -f, -d, -P, -p and -R options, what INFO logs compared with VERBOSE, and that deny is applied before allow.

for a senior

Plan chroot logging (a /dev/log socket per jail on some systems), route a dedicated facility centrally, and check older servers for the pre-10.4 argument truncation.

for a principal

Decide what an audit of partner transfers must prove, then size the log level and retention to that rather than logging everything at DEBUG.

## Why sshd's logs show logins but not files sshd logs authentication: who logged in, with which key, from which address. What the partner then does with files happens inside the **SFTP server**, which has its own logger. For `internal-sftp` the `sshd_config` manual states that, even though it runs in-process, settings such as `LogLevel` and `SyslogFacility` **do not apply to it** and must be set as its own command-line arguments. Its defaults are `-l ERROR` and `-f AUTH`, so an untouched configuration records failures and nothing about successful transfers. ## The options `internal-sftp` takes the `sftp-server` options, written after it on the `ForceCommand` (or `Subsystem`) line: | Option | Meaning | |---|---| | `-l level` | Log level: `QUIET`, `FATAL`, `ERROR` (default), `INFO`, `VERBOSE`, `DEBUG`, `DEBUG1`-`DEBUG3`. `INFO` and `VERBOSE` log the transactions performed for the client. | | `-f facility` | Syslog facility, `AUTH` by default; `DAEMON`, `USER` and `LOCAL0`-`LOCAL7` are the alternatives. | | `-d dir` | Start directory; `%d` expands to the home directory and `%u` to the user name. | | `-P list` | Comma-separated request names to **deny**. | | `-p list` | Comma-separated request names to **allow**; everything else is refused. | | `-R` | Read-only: opens for writing and other changes are refused. | | `-u umask` | Explicit umask for new files and directories. | At `INFO` the server logs `session opened` and `session closed` with the user and address, each `open` with flags and mode, each `close` with **bytes read and written**, and `rename`, `posix-rename`, `remove`, `mkdir` and `rmdir`. At `VERBOSE` it adds lines such as stat and realpath calls and the **refusals** produced by `-P`, `-p` and `-R`. A dedicated facility such as `LOCAL5` lets the syslog daemon route partner transfer logs to their own file or to a central collector. ## Restricting requests `sftp-server -Q requests` prints the request names the lists accept: `open`, `read`, `write`, `remove`, `rename`, `posix-rename`, `mkdir`, `rmdir`, `setstat`, `symlink`, `hardlink`, `copy-data` and more. If both lists are given, **the deny list is applied before the allow list**. Examples: - An upload-only drop that must not read back or delete: `-P read,remove,rmdir,copy-data`. - A download-only account: `-R`. The manual warns that clients make some requests implicitly (resolving paths, checking attributes), so an allow list must include them or ordinary clients break. What each request does on the wire is the request-level material's subject; here the point is which ones a partner may issue. ## Logging from inside a jail On some operating systems the logging library writes to the `/dev/log` socket by path. Inside a chroot that path resolves inside the jail, so the `ChrootDirectory` and `sftp-server` manuals note that a session which logs **may need a `/dev/log` socket inside the chroot**, created by the syslog daemon listening on an extra socket there. With one jail per partner, that is one extra socket per jail. The in-process server still needs no binaries in the jail; only the socket is in question. ## Choosing the level - **`INFO`** is the usual audit setting: one line per session open and close, and per file opened and closed with byte counts, which is enough to answer who delivered which file and how large it was. - **`VERBOSE`** adds the refusals and the read-only lookups; use it when you need evidence that a deny list is working, and expect noticeably more lines per session. - **`DEBUG` levels** are for troubleshooting one account for a short time, not for a standing configuration. ## The 10.4 argument fix ```ini Match Group carriers ForceCommand internal-sftp -l INFO -f LOCAL5 -d /upload -P read,remove,rmdir,copy-data ``` OpenSSH 10.4's release notes list a security fix: with `internal-sftp`, long command lines were **silently truncated after the ninth argument**, so a security-relevant option in the tenth position or later was discarded without an error. A line that grew over time — logging flags, a start directory, a umask, then a deny list at the end — could lose the deny list. On 10.4 and later the whole line applies; on older servers keep restricting options first and test them. ## Verifying 1. Log in as the partner and upload a file; the log should show `open`, then `close` with the byte count. 2. Try a denied request (for example, delete a file under `-P remove`); the client gets a failure, and at `VERBOSE` the server logs the refusal. 3. Check that lines arrive under the chosen facility at the central collector.

  • You set `-P remove` and need to see refused deletes in the log. Which log level shows them?
    `VERBOSE`. The refusal of a denied, non-allowed or read-only request is logged at `VERBOSE`, while `INFO` logs the transactions that succeed, such as opens, closes with byte counts and renames. Set `-l VERBOSE` on the `internal-sftp` line.
  • Why can an allow list with `-p` break ordinary SFTP clients?
    Everything not on the list is refused, and clients issue requests the user never typed, such as resolving the start path or reading attributes before a transfer. The manual warns that those implicit requests must be permitted; test with the partner's real client before rollout.

  • Setting LogLevel VERBOSE in sshd_config logs every file the partner uploads.
  • internal-sftp logs transfers by default because it runs inside sshd.
  • The allow list is applied before the deny list.
  • A chrooted internal-sftp needs a copy of the sftp-server binary to log.
  • Every argument on a long internal-sftp line is honoured on any OpenSSH release.

Assumes OpenSSH 10.5; before 10.4, internal-sftp silently dropped command-line arguments after the ninth, so options at the end of a long ForceCommand line could be lost.