For an OpenSSH SFTP-only partner account, what do the authorized_keys options restrict and from= add, and where should that key file live?
answer
- options in front of the key
- one word for every restriction
- a stolen key from elsewhere
- addresses, not names
- out of the partner's reach
basics
~10 srestrict disables forwarding, PTY allocation and ~/.ssh/rc for that key; from= accepts it only from listed addresses or CIDR ranges. Keep the file outside the partner's writable area, for example AuthorizedKeysFile /etc/ssh/authorized_keys/%u.
solid answer
~50 sOptions at the start of an `authorized_keys` line apply whenever that key is used. `restrict` turns on every restriction at once — no port, agent or X11 forwarding, no PTY, no `~/.ssh/rc` — and future restrictions join it automatically, so the key stays confined even if the server-side Match block is wrong. `from="198.51.100.0/24"` adds a second factor of sorts: the key is accepted only from the partner's egress addresses, so a stolen copy fails elsewhere; with the default `UseDNS no`, only addresses match, not host names. Because `ChrootDirectory %h` turns the home into the jail, the default `.ssh/authorized_keys` would sit inside what the partner can reach; a root-owned `AuthorizedKeysFile /etc/ssh/authorized_keys/%u` in the group's Match block keeps partners from editing their own options. Key-only login for the group is one more line there, such as `AuthenticationMethods publickey`.
code
ini · 8 lines# sshd_config, at the end of the file
Match Group carriers
AuthorizedKeysFile /etc/ssh/authorized_keys/%u
AuthenticationMethods publickey
ChrootDirectory %h
ForceCommand internal-sftp -d /upload
DisableForwarding yes
PermitTTY nogo deeper
Recall the two options: restrict switches off forwarding and terminals for the key, from= limits where it can be used from.
Explain why from= needs addresses under the default UseDNS no, what restrict covers, and why the key file moves out of the jail with AuthorizedKeysFile and %u.
Show the layered policy: Match block, per-key restrict and from=, root-owned key files, and an onboarding record of each partner's ranges so changes do not cause outages.
Weigh the operational cost of address pinning against the protection it buys when a partner's key leaks, and decide who owns key rotation on each side.
## Why the key line carries policy An `authorized_keys` line has an optional **options** field before the key type. OpenSSH applies those options every time that key authenticates. For a partner transfer account this makes the key itself carry the account's limits, which is useful because a server-side Match block can be edited, reordered or matched by the wrong group, while the key line travels with the key. ```ini restrict,from="198.51.100.0/24,203.0.113.17" ssh-ed25519 AAAAC3...illustrative... carrier07-2026 ``` ## `restrict`: everything off in one word `restrict` **enables all restrictions**: it disables port, agent and X11 forwarding, PTY allocation and execution of `~/.ssh/rc`. The manual adds that **any restriction capability added in future** is included in it automatically, which is why it beats listing `no-port-forwarding`, `no-agent-forwarding`, `no-X11-forwarding` and `no-pty` one by one. Individual capabilities can be given back after it (`port-forwarding`, `pty`, `X11-forwarding`, `user-rc`), but a file-drop key needs none of them. For an SFTP-only account the server already forces `internal-sftp` and should already set `DisableForwarding yes`; `restrict` is the per-key backstop for the day that block is wrong. ## `from=`: where the key may be used `from="pattern-list"` requires that, **in addition to** the key, the client's address (or canonical host name) matches one of the patterns. Patterns may use wildcards and **CIDR** notation. The manual's reasoning is exactly the partner case: a key alone trusts nothing but the key, so a stolen copy works from anywhere; tying it to the partner's egress range means an attacker also needs to come from that network. Two practical points: - **Use addresses.** With `UseDNS no` — the default — sshd matches only addresses in `from=`, not host names, so a pattern such as `partner.example.net` never matches. - **Agree the ranges.** A partner that changes its outbound NAT or moves its job to a new network will be refused until the line is updated, so the range belongs in the onboarding record. ## Where the file lives By default `AuthorizedKeysFile` is `.ssh/authorized_keys .ssh/authorized_keys2`, relative to the user's home. With `ChrootDirectory %h` that home **is** the partner's jail, so the key file sits at what the partner sees as `/.ssh/authorized_keys`. sshd reads it during authentication, before the chroot, and the partner may well be able to list it; if a writable `.ssh` or key file ever ends up there, the partner can upload a new copy that drops `from=` and `restrict` or adds keys. The cleaner layout keeps keys entirely outside the jail: | Setting | Where keys live | Partner can edit? | |---|---|---| | default `.ssh/authorized_keys` with `ChrootDirectory %h` | inside the jail | only if `.ssh` or the file is writable; often visible | | `AuthorizedKeysFile /etc/ssh/authorized_keys/%u` in the Match block | root-owned directory | no | `AuthorizedKeysFile` is permitted inside a Match block and accepts the `%u` (user name) token, so the change applies to the partner group only. ## Key-only for the group The policy a transfer account adds is that it never accepts anything but a key. In the same Match block, `AuthenticationMethods publickey` (or turning password methods off for the group) does that. How public-key authentication proves possession of the key, and how methods are switched off server-wide, are the authentication and hardening material's subjects. ## What these options do not do - **They do not confine files.** `restrict` limits what the connection may do besides the session; the jail comes from `ChrootDirectory` and the forced `internal-sftp` server. - **They do not replace key custody.** `from=` makes a stolen key harder to use, not harmless: an attacker inside the partner's network still matches the range. - **They do not make a key shareable.** One key per partner keeps revocation and log attribution per partner; a key copied between partners loses both, whatever its options say. - **They do not survive a writable key file.** Options are only as strong as the file that holds them, which is the reason for the root-owned location above. ## Checklist for one partner key 1. Key generated by the partner; only the public half is sent. 2. Line starts with `restrict` and a `from=` with the agreed addresses. 3. Stored in a root-owned file named for the account, outside the jail. 4. Comment field records who and when, so rotation and removal are easy.
- A partner's key line says `from="files.partner.example.net"` and every login is refused. Why?With the default `UseDNS no`, sshd does not look up host names, so `from=` and Match `Host` patterns can only match addresses. The name pattern never matches the client's address. Replace it with the partner's egress addresses or CIDR range.
- Why is `restrict` preferable to listing `no-port-forwarding,no-agent-forwarding,no-X11-forwarding,no-pty`?`restrict` covers all of those plus `~/.ssh/rc`, and any restriction capability OpenSSH adds later is included automatically, so an old key line does not silently miss a new kind of access. You re-enable only what you need, which for a file drop is nothing.
- from= with a host name works out of the box on a default sshd.
- restrict only disables port forwarding and leaves the PTY alone.
- Keys inside the partner's chroot are safe because sshd reads them after the chroot.
- A from= restriction makes the key safe to share among several partners.
- Key-only login for partners requires turning passwords off for the whole server.