Repository navigation
Conversation
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.
There was a problem hiding this comment.
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.
| # 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) |
There was a problem hiding this comment.
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.
|
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. |
omarchy-setup-security-sshdopens with "Setting up SSH server access with key-based authentication" and never touches the user's password. Nothing in the repo setsPasswordAuthentication, and Arch shipssshd_configwith that line commented out, so the default applies and the server takes passwords from the network. The only guard isufw 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 byomarchy-provision-owner, so it is the root password being offered to the network.The order was the other half of it.
setup_sshdandopen_firewallboth ran before the key was read:So
omarchy-setup-security-sshd --key=not-a-keyinstalled 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_sshdsplits intoinstall_sshdandstart_sshd. Installing still runs first, because the key check callsssh-keygenand the openssh package ships it. Starting the server and opening the port now wait until a key is in place./etc/ssh/sshd_config.d/omarchy-keys-only.confsetsPasswordAuthentication noandKbdInteractiveAuthentication no. It is written before the server starts, so the server never spends a moment listening with password logins on.sshd -Treportspasswordauthentication no. sshd reads the drop-in through anIncludeline and for most keywords the first value it finds wins, so aPasswordAuthenticationline sitting above thatIncludewould 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_sshdreloads 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.shstubssudo,ssh-keygen,omarchy-pkg-addand 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 reachingauthorized_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 loosesshdpattern also matches thesshd_config.dpath in the earlier lines. All 11 pass. Against the old script the rejected-key case fails the way it should, withsystemctl enable --now sshd.serviceand bothufwcalls sitting in the log before the key was ever read, and movingopen_firewallabove the check fails the ordering case../test/shellcomes 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,jqandluaandmagickand others, and not anything this touches../test/clineedsjqand would not run on this machine at all.