Skip to content

Stop the sshd setup from leaving password logins on - #7986

Closed
Adolanium wants to merge 2 commits into
omacom:quattrofrom
Adolanium:sshd-keys-only
Closed

Adolanium wants to merge 2 commits into
omacom:quattrofrom
Adolanium:sshd-keys-only

Conversation

@Adolanium

@Adolanium Adolanium commented Aug 24, 2026 •

Copy link
Copy Markdown
Contributor

omarchy-setup-security-sshd opens with "Setting up SSH server access with key-based authentication" and never touches the user's password. Nothing in the repo sets PasswordAuthentication, and Arch ships sshd_config with that line commented out, so the default applies and the server takes passwords from the network. The only guard is ufw limit 22/tcp, which slows a brute force attempt but does not stop one. On an Omarchy install that password is also the root password, set by omarchy-provision-owner, so it is the root password being offered to the network.

The order was the other half of it. setup_sshd and open_firewall both ran before the key was read:

setup_sshd
open_firewall

echo
if [[ -n $KEY ]]; then

So omarchy-setup-security-sshd --key=not-a-key installed openssh, enabled the server and opened port 22, and only then rejected the key and exited. Pressing escape at the interactive picker did the same. Either way the machine is left listening on port 22 taking passwords, with no key authorized at all. That is the worst state this command can produce and it takes one keypress to reach.

What changed:

  • setup_sshd splits into install_sshd and start_sshd. Installing still runs first, because the key check calls ssh-keygen and the openssh package ships it. Starting the server and opening the port now wait until a key is in place.
  • A drop-in at /etc/ssh/sshd_config.d/omarchy-keys-only.conf sets PasswordAuthentication no and KbdInteractiveAuthentication no. It is written before the server starts, so the server never spends a moment listening with password logins on.
  • The port opens last, and only after sshd -T reports passwordauthentication no. sshd reads the drop-in through an Include line and for most keywords the first value it finds wins, so a PasswordAuthentication line sitting above that Include would beat the drop-in. Asking sshd is the only way to know it landed. If it still reports passwords on, the setup says why and stops with the firewall closed.
  • start_sshd reloads as well as enables, so a server left running by an earlier run picks the drop-in up.

Removing the drop-in goes back to password logins, and the file says so in a comment. The manual line about the SSH port now says the setup turns password logins off, since it did not say either way before.

Tests: new test/shell.d/security-sshd-test.sh stubs sudo, ssh-keygen, omarchy-pkg-add and the rest, then drives three runs: a good key, a key sshd cannot read, and a machine where sshd still reports password logins on. Eleven cases, covering the drop-in contents, the key still reaching authorized_keys, the drop-in landing before the server starts, the check sitting after the start and before the firewall, and both failure paths leaving the firewall closed and the server disabled. Each ordering step is looked up by its whole logged command, since a loose sshd pattern also matches the sshd_config.d path in the earlier lines. All 11 pass. Against the old script the rejected-key case fails the way it should, with systemctl enable --now sshd.service and both ufw calls sitting in the log before the key was ever read, and moving open_firewall above the check fails the ordering case. ./test/shell comes out the same on this branch as on the base commit, 1747 passing here with the 11 new, same 52 failing files either way. Those 52 are tools missing from my environment, jq and lua and magick and others, and not anything this touches. ./test/cli needs jq and would not run on this machine at all.

The setup announces key-based authentication and never touches the user's
password, but nothing turned PasswordAuthentication off, so the server took
passwords from the network. It also enabled sshd and opened port 22 before
reading the key, so a rejected key left the machine listening with no key
authorized.

Install first, authorize the key, write a keys-only drop-in, start the server,
confirm the setting with sshd -T, and only then open the firewall.
Copilot AI balanced review requested due to automatic review settings August 24, 2026 03:40

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Hardens SSH setup by requiring key-based authentication before exposing the service.

Changes:

  • Installs SSH before key validation but delays service/firewall activation.
  • Adds and validates a keys-only SSH configuration.
  • Adds documentation and shell tests.

Tip

If you aren't ready for review, convert to a draft PR.
Click "Convert to draft" or run gh pr ready --undo.
Click "Ready for review" or run gh pr ready to reengage.

Reviewed changes

Copilot reviewed 2 out of 3 changed files in this pull request and generated 1 comment.

File Description
bin/omarchy-setup-security-sshd Configures keys-only SSH and reorders activation.
test/shell.d/security-sshd-test.sh Tests configuration and activation ordering.
manual/48-security.md Documents disabled password logins.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread test/shell.d/security-sshd-test.sh Outdated
# port only opens once sshd confirms password logins are off.
config_line=$(grep -n 'tee' "$test_tmp/good/sshd.log" | head -1 | cut -d: -f1)
start_line=$(grep -n 'enable' "$test_tmp/good/sshd.log" | head -1 | cut -d: -f1)
check_line=$(grep -n 'sshd' "$test_tmp/good/sshd.log" | grep -v enable | grep -v reload | head -1 | cut -d: -f1)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, this was a real hole. The log lines are tab separated and two earlier ones carry the sshd_config.d path:

sudo	mkdir	-p	/etc/ssh/sshd_config.d
sudo	tee	/etc/ssh/sshd_config.d/omarchy-keys-only.conf
...
sudo	sshd	-T
sudo	ufw	limit	22/tcp	comment	omarchy-sshd

So grep -n 'sshd' landed on the mkdir at line 2 rather than the check at line 7, and the assertion compared 2 against the firewall line. It passed for the wrong reason and would have kept passing with the check moved below open_firewall.

Fixed in 0ec3513. Each step is now looked up with grep -Fxn against the whole logged command, and there is a guard that fails if any of the four lines is missing, so a renamed step cannot silently turn an assertion into a comparison of empty strings.

I also added the other half of the ordering. The check has to sit after the server starts, not just before the firewall opens, because sshd -T wants host keys and the first start is what creates them.

Verified both directions: moving open_firewall above the check now fails with "the firewall opens only after sshd confirms the setting", and against the original script the rejected-key case still fails the way it should.

The ordering assertions searched the stub log for "sshd", which also matches
the sshd_config.d path in the mkdir and tee lines. The first hit was the
mkdir, not the sshd -T call, so the check read as correctly placed even when
it was not.

Match the whole logged command instead, and assert the check sits after the
server starts as well as before the firewall opens.
@ErikMelton

Copy link
Copy Markdown
Member

Since this PR was opened, quattro has gained substantially more SSH hardening and migration logic, making this implementation conflict with and partially regress the current approach. The remaining activation-order issue is now addressed comprehensively in #9463, so I’m closing this as superseded rather than invalid.

@ErikMelton ErikMelton closed this Sep 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants