OutputFormat,
SecureBootSignTool,
ShimBootloader,
+ Ssh,
Verb,
Verity,
Vmm,
def configure_ssh(context: Context) -> None:
- if not context.config.ssh:
+ if context.config.ssh in (Ssh.never, Ssh.runtime):
+ return
+
+ if (
+ context.config.ssh == Ssh.auto
+ and (context.root / "usr/lib/systemd/system-generators/systemd-ssh-generator").exists()
+ ):
+ # systemd-ssh-generator is installed, so we don't need to configure SSH.
return
unitdir = context.root / "usr/lib/systemd/system"
vmspawn = enum.auto()
+class Ssh(StrEnum):
+ always = enum.auto()
+ auto = enum.auto()
+ runtime = enum.auto()
+ never = enum.auto()
+
+
class Incremental(StrEnum):
yes = enum.auto()
no = enum.auto()
autologin: bool
make_initrd: bool
- ssh: bool
+ ssh: Ssh
selinux_relabel: ConfigFeature
secure_boot: bool
),
ConfigSetting(
dest="ssh",
- metavar="BOOL",
section="Content",
- parse=config_parse_boolean,
+ parse=config_make_enum_parser_with_boolean(Ssh, yes=Ssh.always, no=Ssh.never),
+ default=Ssh.auto,
+ choices=Ssh.choices(),
help="Set up SSH access from the host to the final image via 'mkosi ssh'",
),
ConfigSetting(
Autologin: {yes_no(config.autologin)}
Make Initrd: {yes_no(config.make_initrd)}
- SSH: {yes_no(config.ssh)}
+ SSH: {config.ssh}
SELinux Relabel: {config.selinux_relabel}
"""
Architecture: enum_transformer,
BiosBootloader: enum_transformer,
ShimBootloader: enum_transformer,
+ Ssh: enum_transformer,
Bootloader: enum_transformer,
Compression: enum_transformer,
ConfigFeature: enum_transformer,
Firmware,
Network,
OutputFormat,
+ Ssh,
VsockCID,
finalize_term,
format_bytes,
sandbox=config.sandbox(options=["--become-root", "--ro-bind", "/etc/passwd", "/etc/passwd"]),
).stdout.strip()
creds["ssh.authorized_keys.root"] = sshpubkey
- elif config.ssh:
+ elif config.ssh in (Ssh.always, Ssh.runtime):
die(
"Ssh= is enabled but no SSH certificate was found",
hint="Run 'mkosi genkey' to automatically create one",
used as an initramfs.
`Ssh=`, `--ssh=`
-: If specified, an **sshd** socket unit and matching service are installed
- in the final image that expose SSH over VSock. When building with this
+: Specifies whether to install an **sshd** socket unit and matching service
+ in the final image. Takes one of `always`, `never`, `auto` or `runtime`.
+ Defaults to `auto`. If set to `auto` and `systemd-ssh-generator`
+ is not preset in the image, or set to `always`, mkosi will install **sshd** units
+ in the final image that expose SSH over VSock. If set to `never`,
+ mkosi will not install the **sshd* units. If the `runtime` value is used,
+ mkosi will also not install any units but abort starting `mkosi vm` if no
+ SSH credentials are configured. When building with this
option and running the image using `mkosi vm`, the `mkosi ssh`
command can be used to connect to the container/VM via SSH. Note that
you still have to make sure openssh is installed in the image to make
`SshKey=`, `--ssh-key=`
: Path to the X.509 private key in PEM format to use to connect to a
virtual machine started with `mkosi vm` and built with the `Ssh=`
- option enabled via the `mkosi ssh` command. If not configured and
- `mkosi.key` exists in the working directory, it will automatically be
- used for this purpose. Run `mkosi genkey` to automatically generate
- a key in `mkosi.key`.
+ option enabled (or **systemd-ssh-generator** installed) via the `mkosi ssh` command.
+ If not configured and `mkosi.key` exists in the working directory,
+ it will automatically be used for this purpose.
+ Run `mkosi genkey` to automatically generate a key in `mkosi.key`.
`SshCertificate=`, `--ssh-certificate=`
: Path to the X.509 certificate in PEM format to provision as the SSH
OutputFormat,
SecureBootSignTool,
ShimBootloader,
+ Ssh,
UKIProfile,
Verb,
Verity,
"uki",
"kernel"
],
- "Ssh": false,
+ "Ssh": "auto",
"SshCertificate": "/path/to/cert",
"SshKey": null,
"StorageTargetMode": "enabled",
split_artifacts=[ArtifactOutput.uki, ArtifactOutput.kernel],
ssh_certificate=Path("/path/to/cert"),
ssh_key=None,
- ssh=False,
+ ssh=Ssh.auto,
storage_target_mode=ConfigFeature.enabled,
sync_scripts=[Path("/sync")],
sysupdate_dir=Path("/sysupdate"),