Skip to content

fix: Allow SSH on first boot - #4676

Open
CooperWang0912 wants to merge 5 commits into
archlinux:masterfrom
CooperWang0912:feat/ufw-configuration-option
Open

fix: Allow SSH on first boot#4676
CooperWang0912 wants to merge 5 commits into
archlinux:masterfrom
CooperWang0912:feat/ufw-configuration-option

Conversation

@CooperWang0912

@CooperWang0912 CooperWang0912 commented Jul 28, 2026

Copy link
Copy Markdown

PR Description

image

Technical Details

  1. Added confirmation page function confirm_ufw that is called in guided.py, which prompts the user to allow SSH when both ufw and OpenSSH are present.[Note 2] The implementation is as follows:
async def confirm_ufw(config: ArchConfig) -> bool:
	firewall_config = config.app_config.firewall_config
	is_ufw = firewall_config and firewall_config.firewall and firewall_config.firewall.value == 'ufw'
	has_openssh = 'openssh' in config.packages

	if not (is_ufw and has_openssh):
		return True

	else:
		header = f'{tr("You have both ufw and OpenSSH in your packages")}. '
		header += tr('Would you like to allow incoming SSH connections through the firewall?') + '\n'
		group = MenuItemGroup.yes_no()

		result = await Confirmation(
			group=group,
			header=header,
			allow_skip=False,
			preset=True,
		).show()

		if result and result.get_value():
			config.app_config.firewall_config.allow_ssh = True

	return True
  1. Created helper function _allow_ufw_ssh_on_first_boot, which creates a service on first boot that enables SSH. The implementation is seen below:
def _allow_ufw_ssh_on_first_boot(self, install_session: Installer) -> None:
	service_content = """[Unit]
		Description=Allow SSH in UFW on first boot
		After=ufw.service
		Wants=ufw.service
		[Service]
		Type=oneshot
		ExecStart=/usr/bin/ufw allow SSH
		ExecStartPost=/usr/bin/systemctl disable ufw-allow-ssh.service
		[Install]
		WantedBy=multi-user.target
	"""
	service_path = install_session.target / 'etc/systemd/system/ufw-allow-ssh.service'
	service_path.write_text(service_content)
	install_session.enable_service(['ufw-allow-ssh.service'])
  1. Updated the FirewallConfiguration and other relevant classes to include the field allow_ssh

Tests and Checks

  • I have tested the code!

SSH is successfully enabled on first boot.

image

Notes:

  1. Thanks to @KsanDjordje for coming up with this idea
  2. If this approach seems too extreme and disruptive to the overall flow of the installation process, we can also remove the confirmation page in favor of a warning that points the user to the allow_ssh field in the Application -> Firewall tab, similar to the network configuration warning

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.

Installing ufw together with sshd does not add the corresponding ssh ufw allow rule

1 participant