In OpenSSH's sshd_config, what does the default PermitRootLogin prohibit-password still allow, and why do hardening guides set it to no?
answer
- root is not fully locked out
- keys yes, typed secrets no
- four values, one deprecated alias
- who did it, in the logs
- escalation as a second step
basics
~20 sOpenSSH's default PermitRootLogin prohibit-password still lets root log in with a public key; it only refuses password and keyboard-interactive. Hardening sets no so people log in as themselves and escalate with sudo, leaving a per-person trail.
solid answer
~50 s`PermitRootLogin` takes `yes`, `prohibit-password` (the default since OpenSSH 7.0; `without-password` is its deprecated alias), `forced-commands-only` or `no`. With the default, root cannot log in with a password or keyboard-interactive, but a key in root's `authorized_keys` still opens a full root shell. Hardening guides set `no` for three reasons: a root login is recorded as root, leaving at best a key fingerprint to trace back to a person; one copied root key is total control with no second step; and `no` is unambiguous, whereas the `sshd_config` OpenSSH ships warns that, depending on the PAM configuration, PAM through keyboard-interactive may bypass `prohibit-password`. Administrators then log in as named users and use `sudo`. Where a job truly needs root over SSH, such as a backup pull, `forced-commands-only` accepts a root key only when its `authorized_keys` entry pins a `command=`.
go deeper
Recall the four values and that the default, prohibit-password, still allows a root key login. Say what you set instead: no, plus named accounts that escalate with sudo.
Explain which methods each value permits, that the check happens during user authentication after key exchange, and how forced-commands-only with command= covers a job that needs root.
Show production judgment: per-person accountability, a Match Address exception for one backup host instead of a global relaxation, and why the shipped PAM caveat makes no the unambiguous choice.
Frame root SSH as an accountability and blast-radius decision: named identities and escalation policy belong to the access model, and every exception should be narrow, addressed and reviewed.
## What the directive controls `PermitRootLogin` is an `sshd_config` keyword that decides whether the account named `root` may complete **SSH user authentication**, and with which methods. It is evaluated during user authentication, which happens after key exchange: the requested user name only arrives in the authentication request, inside the encrypted transport. So a client that asks for root still completes the handshake; the directive decides whether any of its authentication attempts can succeed. The keyword accepts four values (plus one deprecated alias): | Value | Root may log in with | Typical use | |---|---|---| | `yes` | any enabled method, passwords included | the default before OpenSSH 7.0; avoid on exposed hosts | | `prohibit-password` (alias `without-password`) | public key and other non-interactive methods; password and keyboard-interactive are refused | **the default since 7.0**, still the default in 10.5 | | `forced-commands-only` | public key only, and only when that key's `authorized_keys` entry carries a `command=` option | one job that must run one command as root | | `no` | nothing | the hardened setting for internet-facing servers | The most common mistake is the claim that "root login is disabled by default". It is not: with no `PermitRootLogin` line at all, anyone holding a key listed in root's `authorized_keys` file gets a root shell. ## Why the default is not enough on an exposed server - **Accountability.** sshd logs the account that logged in. If several administrators share root's `authorized_keys`, every session is logged as root, and attributing one means tracing a key back to a person. With named accounts, the log names a person, and the escalation to root is a second, separately logged step. - **Blast radius.** A root key copied off a laptop or out of a backup is complete control of the host with nothing in between. A named account's key still leaves the attacker facing whatever escalation policy the host enforces. - **No ambiguity.** The `sshd_config` that OpenSSH ships carries a comment warning that, depending on the PAM configuration, PAM authentication through `KbdInteractiveAuthentication` may bypass `PermitRootLogin prohibit-password`. `no` has no such corner: every root attempt fails. - **Audit readability.** An auditor reading `PermitRootLogin no` needs no knowledge of which keys sit in root's home directory. ## What to set instead 1. Create named administrator accounts with their own keys and grant them `sudo` through a group. 2. Set `PermitRootLogin no` in the global section of `sshd_config`. 3. Keep an out-of-band recovery path (a console) that does not depend on root SSH; how to change and reload sshd without locking yourself out is covered by the material on OpenSSH operations. 4. If a job genuinely needs root over SSH, scope it rather than relaxing the global setting. `PermitRootLogin` is one of the keywords allowed inside a `Match` block, so the exception can be pinned to one source address: ```ini PermitRootLogin no Match Address 192.0.2.10 PermitRootLogin forced-commands-only ``` Here only connections from the backup host at 192.0.2.10 may use root, and only with a key whose `authorized_keys` line names the one command it may run. ## Common confusions - **`no` does not block `sudo` or `su`.** The directive governs SSH authentication of the account named root. After alice logs in as herself, local escalation works exactly as the host's policy allows. - **`prohibit-password` is not a weaker `no`.** It is a different policy: keys are accepted. Treat it as "root by key", not "root off". - **It does not replace switching passwords off for everyone else.** `PermitRootLogin` only concerns root; `PasswordAuthentication` and `KbdInteractiveAuthentication` decide whether other accounts can use typed secrets. - **The refusal happens at authentication, not at connect.** Failed root attempts still count as failed authentication, which sshd's own per-source penalties treat like any other failure. ## Reading an existing configuration When you audit a server, the absence of a line is itself an answer: - **No `PermitRootLogin` line** means `prohibit-password`, so check whether root's `authorized_keys` holds any keys at all. - **A line in an included drop-in file** counts: sshd keeps the first value it obtains for most keywords, so a drop-in read early can set the value before the main file does. - **A `Match` block** further down can override the global value for some users or addresses; read every block, not just the top of the file. - `sshd -T` prints the value actually in force, which settles disagreements between files. ## In an interview State the default precisely (prohibit-password, keys still work), give the accountability and blast-radius reasons for `no`, and show the scoped exception with `forced-commands-only` in a `Match Address` block. That combination shows you know both the directive and why it exists.
- Does PermitRootLogin no stop an administrator from becoming root after logging in over SSH?No. The directive only governs SSH user authentication for the account named root. Once alice logs in as herself, `sudo` or `su` work exactly as local policy allows. That is the point: escalation becomes a second, separately logged step tied to a named person.
- A nightly backup must run one command as root from a single backup host. How do you allow that without reopening root logins?Keep `PermitRootLogin no` globally and add a `Match Address` block for the backup host that sets `PermitRootLogin forced-commands-only`. Root's `authorized_keys` entry for the backup key carries `command=` naming the one script, so that key runs nothing else and no other address can use root at all.
- Why does sshd still complete key exchange with a client that asks to log in as root when PermitRootLogin is no?The user name only arrives in the user-authentication request, which is sent inside the encrypted transport after key exchange. sshd cannot refuse root before it knows the requested name, so the refusal happens at authentication, and those failures count against the source like any other failed login.
- OpenSSH disables root login over SSH by default.
- prohibit-password blocks root completely, so setting no changes nothing.
- PermitRootLogin no also stops users running sudo after they log in.
- forced-commands-only lets a root key run any command it likes.
- sshd refuses root before key exchange because it sees the user name first.
Assumes OpenSSH 10.5; prohibit-password has been the PermitRootLogin default since 7.0, which replaced yes.