Skip to content

Keep SSH setup from disabling passwords on a writable home - #9506

Open
mark-groves wants to merge 4 commits into
omacom:quattrofrom
mark-groves:fix/sshd-setup-strictmodes-home
Open

mark-groves wants to merge 4 commits into
omacom:quattrofrom
mark-groves:fix/sshd-setup-strictmodes-home

Conversation

@mark-groves

@mark-groves mark-groves commented Aug 31, 2026 •

Copy link
Copy Markdown
Contributor

Why

OpenSSH StrictModes is on by default. When $HOME is group-writable or world-writable, sshd ignores authorized_keys.

omarchy-setup-security-sshd already runs chmod 700 on ~/.ssh and chmod 600 on the keys file. It then writes PasswordAuthentication no to /etc/ssh/sshd_config.d/10-omarchy-hardening.conf and prints that password logins are off. If $HOME is mode 775 or 777, that write closes the only login sshd still accepted. New SSH sessions get neither a key nor a password.

migrations/1788124236.sh already refuses to harden in that case. The skip text tells you to run omarchy-setup-security-sshd. That command still writes the drop-in.

The patch adds the same home-mode check to disable_password_auth.

Scope

bin/omarchy-setup-security-sshd, disable_password_auth only.

After the empty-key return, the function stats $HOME. If stat fails, the function returns 1. If the mode has group-write or other-write (8#022), the function returns 1. It does not write 10-omarchy-hardening.conf and does not reload sshd.

test/shell.d/setup-security-sshd-test.sh adds a HOME_MODE hook on run_setup and a 775 case named loose-home. That case must fail the command, leave the drop-in unwritten, skip systemctl reload sshd.service, and print the writable-home error.

This PR does not chmod $HOME. It does not check ownership or ACLs. It does not include the rewrite in #9463 that proves key-only access before it starts sshd.

Tradeoffs

If the function returns 1, sshd stays enabled and port 22 stays open. Password logins stay on. The authorized key stays in place and StrictModes still ignores it. That is the machine's prior state. A chmod of $HOME would make the key work, but the home directory is not this command's to change. The migration made the same call.

A 700 or 755 home still hardens. Those are the modes Arch HOME_MODE and a typical umask create.

Blast Radius

The check runs for every omarchy-setup-security-sshd invocation, including the Setup menu and the --key or --gh-keys flags.

On a default Omarchy install $HOME is 700. Mode 755 is also safe. The new return fires only when $HOME has group-write or world-write. A user at the desktop still has local login. The unattended flags are the case where a false "passwords are off" line matters more.

The predicate matches the migration. A 775 home that the migration already skips now gets the same refusal from the command the skip text names.

Verification

Ran ./test/shell.d/setup-security-sshd-test.sh on af887538. All five cases passed, including SSH setup leaves passwords on when the home directory is group-writable.

The companion migration already refuses to harden when StrictModes would ignore authorized_keys. The interactive setup command did not, so it could write PasswordAuthentication no and report key-only access on a group- or world-writable home.
@omarchybot omarchybot added bug Something isn't working verified Omarchy Triage has verified that this issue is ready for final review labels Sep 27, 2026
@omarchybot

Copy link
Copy Markdown
Collaborator

Reviewed at af887538 against quattro and verified on a disposable Omarchy worker. The bug is real and this fixes it; nothing found to change.

The bug, reproduced with a real sshd. A throwaway user with a key in ~/.ssh/authorized_keys (dir 700, file 600) logs in with the key when their home is 700 or 755. At 775 or 777, sshd logs Authentication refused: bad ownership or modes for directory and refuses the key. Running omarchy-setup-security-sshd --key=… from quattro as that user with a 775 home exits 0, writes 10-omarchy-hardening.conf, and prints "Password logins are off". Afterwards sshd offers only publickey and refuses the key, so neither the key nor the password gets in.

This branch on the same machine. With a 775 home it exits 1 with the writable-home message. It writes no drop-in, and sshd still offers publickey,password. With a 755 home it hardens as before, and the key logs in.

Tests on the worker: test/shell.d/setup-security-sshd-test.sh passes 5/5 on this head. With only the script reverted to quattro, the new loose-home case fails. test/shell.d/sshd-hardening-migration-test.sh passes 15/15, and ./test/cli is green.

The check matches what migrations/1788124236.sh already does, so the command that migration's skip message points users to now refuses in the same case. The diff is the size of the problem.

Second opinion: none. The reviewer, Codex Medium, was reachable, but today's review budget was already spent. So this is one model's review, by Claude Opus 5.5.

Related: #9463, a draft that conflicts with quattro, carries the same predicate inside a much larger SSH rewrite. #9043 moves the authorized keys to the invoking user's home under sudo. If it lands after this, the new check should stat that same home rather than $HOME.

This now waits on a second-opinion review and then on the maintainer.

@omarchybot omarchybot removed the verified Omarchy Triage has verified that this issue is ready for final review label Nov 3, 2026
omarchybot and others added 2 commits November 16, 2026 21:39
omacom#14667 reordered setup so sshd starts and ufw opens only after passwords are off, and replaced the test's reload assertions with assert_nothing_exposed. The loose-home case now uses it too, so a refused writable home is shown to start nothing and open nothing, not merely to skip a reload.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
sshd resolves the home directory before checking its modes under StrictModes, so a home that is a symlink to a 755 directory accepts keys. stat without -L read the link's own 777 and refused to harden it, with a message telling the user their home was writable when it was not. With -L the guard checks what sshd checks, and still refuses a symlink to a writable directory.

Co-Authored-By: Codex Medium <noreply@openai.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@omarchybot omarchybot added the verified Omarchy Triage has verified that this issue is ready for final review label Nov 16, 2026
The homes were made by mkdir -p under the ambient umask, so under umask 002 every case's home was 775 and the new writable-home guard failed them all. run_setup now sets 755 unless a case asks for another mode.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@greptile-apps

greptile-apps Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; the previous test-permission issue is fixed.

Summary

SSH setup refuses to disable passwords when the home directory is writable by others or its permissions cannot be read.

  • SSH setup keeps password logins on when it cannot verify the home.

Reviews (2) · Last reviewed commit: "Give the sshd test homes an explicit mod..." · Reviewed by Greptile

@omarchybot omarchybot added verified Omarchy Triage has verified that this issue is ready for final review and removed verified Omarchy Triage has verified that this issue is ready for final review labels Nov 16, 2026
@omarchybot

Copy link
Copy Markdown
Collaborator

This branch had stopped merging after #14667 reordered SSH setup on quattro, so I merged quattro into it and pushed two small fixes on top. It is verified again at afc373e2, and CI is green.

The merge (5109aa93). The script merged cleanly, and the conflict was only in the test. #14667 replaced the reload checks with assert_nothing_exposed, so the loose-home case uses that now too. It also checks that a refused writable home starts nothing and opens no firewall port, not just that sshd skipped a reload. Since #14667, a refusal here exits before sshd starts or the port opens. So the description's note that sshd stays enabled and port 22 stays open only holds if sshd was already running before setup.

Symlinked home (1af1f7c5). stat -c '%a' "$HOME" reads a symlink's own mode, which is always 777. sshd resolves the home before checking it. On the worker, a user whose home is a symlink to a 755 directory logs in with their key and no drop-in. The guard refused to harden that home and printed that it was writable. It now uses stat -L. A symlink to a 775 directory is still refused. A new linked-home case fails without -L.

Test umask (afc373e2). The test homes were created under the ambient umask. With umask 002, every case's home was 775, so the new guard failed them all. run_setup now sets 755 unless a case asks for another mode. On the worker, the previous head failed under umask 002, and this head passes under both 022 and 002.

Verified on a disposable Omarchy worker with a real sshd (OpenSSH 10.6p2). I used a throwaway user with a 775 home and set it up with --key:

  • quattro's script exited 0, wrote 10-omarchy-hardening.conf and said "Password logins are off". sshd then refused the key ("bad ownership or modes for directory") and offered only publickey, so neither the key nor the password gets in.
  • This branch exits 1 with the writable-home message and writes no drop-in, and sshd still offers publickey,password.
  • With a 755 home, both harden and the key logs in.

test/shell.d/setup-security-sshd-test.sh passes 8/8. With only the script reverted to quattro, loose-home fails. ./test/cli is green.

Second opinion. Codex Medium and muse-wonder (via pi, thinking high) reviewed it in three rounds, each on the head it was asked about, and the last round found nothing open. Codex proposed the stat -L change, and both agreed with it once it was verified (their independence from this review is not guaranteed). Asked to compare this PR with #9474, they first favoured the older PR. Given that #9474's SSH half is the design of #9463, which was closed when #14667 landed, they chose this one.

Still open, for the maintainer: like the migration, the guard checks only that $HOME is not group- or world-writable. sshd also refuses a home owned by someone other than the user or root, and a writable directory above it. Whether to check those as well is a scope call. The PR description still lists #9463 as the alternative, but that PR is closed, and #14667 shipped its ordering change.

This waits on the maintainer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working verified Omarchy Triage has verified that this issue is ready for final review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants