Skip to content

SSH keys and agents ​

[bootstrap.ssh] declares a machine's SSH trust instead of hand-editing it over SSH:

mise manages public keys and points ssh at agents. It is not a key agent, and it never creates, reads, or copies a private key. Keep private keys in hardware, behind an agent such as Secretive (the Mac's Secure Enclave), ssh-tpm-agent (a Linux TPM), or a security key, and give mise only their .pub lines.

These sections work on Linux and macOS.

Example: CI hosts that accept only hardware keys ​

A fleet of Mac mini CI runners accepts exactly two keys for the maintainer account: the maintainer's Secretive key, held in the Secure Enclave of their Mac, and the TPM-sealed key of bamboo, a Linux box that drives the fleet. A key on disk, such as an old id_ed25519, must not work. The policy is two lines, so it is easy to review:

# mise.mac-ci.toml, applied to each runner
[bootstrap.ssh.authorized_keys.jdx]
mode = "exact"
key_files = [
  "keys/jdx-secretive.pub", # ecdsa-sha2-nistp256, Secure Enclave
  "keys/bamboo-tpm.pub",    # ecdsa-sha2-nistp256, bamboo's TPM
]

The .pub files live in the config repository next to this file. Preview the change before you apply it; in exact mode the dry run lists every key it would remove and the diff of the file. -E mac-ci loads mise.mac-ci.toml:

sh
mise -E mac-ci bootstrap ssh apply --dry-run
text
mise WARN  ssh: exact authorized_keys for jdx removes 1 key(s) the config does not declare:
mise WARN  ssh:   - ssh-ed25519 SHA256:pB1u4C0... jdx@old-laptop
--- /Users/jdx/.ssh/authorized_keys
+++ /Users/jdx/.ssh/authorized_keys (desired)
...
mise ssh: the current file is saved to /Users/jdx/.ssh/authorized_keys.mise-backup-20261128T153000 first
would create directory /Users/jdx/.ssh
would write file /Users/jdx/.ssh/authorized_keys.mise-backup-20261128T153000
would write file /Users/jdx/.ssh/authorized_keys

On the maintainer's Mac, every host uses Secretive's agent:

[bootstrap.ssh.config."*"]
identity_agent = "secretive"

On bamboo, the runner entries use the TPM agent, and offer only the TPM key:

[bootstrap.ssh.config."mac-ci-*"]
user = "jdx"
identity_agent = "~/.ssh/tpm-agent.sock"
identity_file = "~/.ssh/id_ecdsa_tpm.pub"
identities_only = true

IdentityFile names the .pub file, which tells ssh which of the agent's keys to offer; the private half never leaves the TPM. See Run ssh-tpm-agent for the agent itself.

Authorized keys ​

Each table under [bootstrap.ssh.authorized_keys] is named after a local user and writes that user's ~/.ssh/authorized_keys:

[bootstrap.ssh.authorized_keys.deploy]
keys = [
  "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIIdM/MDuMaebX95SANsoQ+GnX3Ogc4IDx6RAYmLvp933 ci@example",
  'from="10.0.0.0/8",no-pty ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBDF8ui0ORl/Abze/g20BYijE4hFFtXr6pII+T5NyQBsfwp8cemP10sSOp7+a7r4mAMDMRX74VnzU+QD5x+Nv1tU= backup',
]
key_files = ["keys/alice.pub"]
KeyMeaning
keysauthorized_keys lines: optional options, the key type, the base64 key, and an optional comment
key_filesfiles of such lines, such as .pub files, relative to the declaring config file or starting with ~/; blank lines and # comments are skipped
mode"ensure" (the default) adds the declared keys and keeps the others; "exact" writes only the declared keys
osOS or OS/arch selectors, as for system files; the entry is skipped elsewhere

mise checks every declared line before it writes anything: a line that is not a public key, a key whose base64 does not decode to its stated type, an option sshd does not know (such as no-ptty, which makes sshd ignore the whole line) or a value it rejects (such as permitopen="host" without a port), or a line that holds two keys run together is an error, which names the entry and the file the line came from.

Ensure and exact ​

mode = "ensure" adds each declared key the file lacks, on a line of its own, and keeps every other line as it is. A key counts as present when the file holds the same key type and base64, whatever its comment. When the file authorizes a declared key with other options, mise keeps that line and warns, since replacing it would change what the key may do; use exact mode for that. Ensure never removes a key.

mode = "exact" writes a header comment and then exactly the declared keys, in the order declared, and removes every other line. Before it replaces a file whose content differs, mise saves the old file next to it as authorized_keys.mise-backup-<timestamp>, with the same owner and mode 0600. The dry run and apply both list each key that is removed, by type, SHA256 fingerprint, and comment, and the dry run prints the diff.

Don't lock yourself out ​

Exact mode can remove the key you are logged in with. When mise runs over SSH (SSH_CONNECTION, SSH_CLIENT, or SSH_TTY is set) or under sudo, an exact entry for the user you log in as is refused when:

  • sshd exposes the keys this session authenticated with (ExposeAuthInfo yes, read from SSH_USER_AUTH), and any one of them would be dropped. A login that needed two keys (AuthenticationMethods publickey,publickey) needs both kept. Or
  • sshd does not expose them, the file authorizes at least one key now, and none of those keys stays. Or
  • sshd does not expose them, or exposes one mise cannot read, and the file has a line mise cannot read as a key, such as a key type it does not know. Exact mode removes that line, and it may be the one you log in with.

A key stays only when the lines that authorize it now come first among its declared lines, with the same options and in the same order; a new line for that key goes after them. sshd uses the first line for a key that lets the client in, so a changed, reordered, or inserted line may change which one applies. Adding from= or restrict to the key you log in with may refuse your next login, and mise cannot tell whether it would, so that also needs --force.

text
mise ERROR refusing to apply [bootstrap.ssh.authorized_keys] in exact mode, which could lock you out of this SSH session:
  /Users/jdx/.ssh/authorized_keys: no key authorized now stays authorized with the same options
Add a key you log in with to the config, or run `mise bootstrap ssh apply --force` if you have another way in.

Nothing is written when the guard refuses. A dry run warns instead of failing. mise bootstrap ssh apply --force applies the entry anyway; the full mise bootstrap has no such flag, so run the forced apply on its own first. Under sudo, the user you log in as is SUDO_USER.

Keep a second session open while you change the keys of a remote machine, and test a new login before you close it.

Files mise writes ​

PathOwnerMode
~<user>/.sshthe user0700
~<user>/.ssh/authorized_keysthe user0600
~<user>/.ssh/authorized_keys.mise-backup-*the user0600

Every line mise writes ends with a newline, and ensure mode first adds the missing newline at the end of a file that lacks one, so an appended key is never glued onto the last line. mise bootstrap ssh status warns about a line that already holds two keys run together, since only the first of them works.

For your own user, mise reads and writes under $HOME as you, never through sudo, so your files stay yours. That holds for ~/.ssh/config too. A file of yours that mise cannot read or change is an error naming it. When $HOME belongs to someone else, as it can under sudo, mise uses the home directory the account database names for you instead, so root never writes its files into another user's home. For another user, it writes under the home directory the account database names, as that user's owner and primary group. That change runs as root: through sudo unless mise already runs as root, as with system files. Reading another user's file to compare it also uses sudo. The user must exist; to create one, see Linux users and groups, which mise bootstrap applies first.

Client Host entries ​

[bootstrap.ssh.config] writes Host entries into your ~/.ssh/config. Each key is a Host pattern, or several separated by spaces:

[bootstrap.ssh.config."build-*.internal"]
user = "ci"
port = 2222

[bootstrap.ssh.config.bastion]
hostname = "203.0.113.10"
identity_agent = "1password"
Keyssh_config optionValue
hostnameHostNamethe real host name or address
userUserthe user to log in as
portPortthe port
identity_agentIdentityAgentan agent socket path, "none", "SSH_AUTH_SOCK", or an agent name
identity_fileIdentityFilethe key to offer; for an agent's key, its .pub file
identities_onlyIdentitiesOnlytrue to offer only the configured identity
osnoneOS or OS/arch selectors; the entry is skipped elsewhere

mise keeps the entries between two marker comments and leaves the rest of the file alone:

text
Host personal
  User me
# >>> mise:ssh >>> managed by mise — do not edit between markers
Host build-*.internal
  User ci
  Port 2222

Host bastion
  HostName 203.0.113.10
  IdentityAgent "~/Library/Group Containers/2BUA8C4S2C.com.1password/t/agent.sock"

# what follows applies to every host again
Match all
# <<< mise:ssh <<<

Apply replaces what is between the markers, appends the region when the file has none, and creates the file when it is missing. It works like a block in a system file: ~/.ssh/config must be a regular file, so a symlinked dotfile is refused. Removing every entry from the config leaves the last region in place; delete it by hand.

ssh uses the first value it finds for each option, reading the file from the top. Entries are written in the order declared, except that a Host * entry goes last, so a specific entry can override it. Your own lines above the region come first, so a Host * of yours with an IdentityAgent wins over the region's; move it below the region or into the config. The region ends with Match all, so your lines below it apply to every host, as they would without the region, and not only to its last entry.

A value with a space or an apostrophe, or one that starts with #, is written in double quotes. A value that holds a double quote or a newline is rejected, and so is a Host pattern with a quote or apostrophe in it.

Entries merge by Host pattern across the config hierarchy: the most local declaration of a pattern is used as a whole.

Agents ​

identity_agent accepts the name of an app that keeps keys in hardware or a vault, and writes that app's socket path:

NamePlatformSocket
"secretive"macOS~/Library/Containers/com.maxgoedjen.Secretive.SecretAgent/Data/socket.ssh
"1password"macOS~/Library/Group Containers/2BUA8C4S2C.com.1password/t/agent.sock
"1password"Linux~/.1password/agent.sock

Status and apply warn when the socket does not exist yet, which usually means the app is not installed or not running. mise does not install these apps. Secretive is a GUI app; to install it with mise, add its cask to [bootstrap.packages]:

[bootstrap.packages]
"brew-cask:secretive" = "latest"

Run ssh-tpm-agent ​

mise has no built-in support for ssh-tpm-agent yet, but the existing sections cover it. On bamboo the agent runs as a system unit for one user, with access to the TPM through the tss group:

# where your distribution packages ssh-tpm-agent
[bootstrap.packages]
"apt:ssh-tpm-agent" = "latest"

# add jdx to tss; other groups and fields of the account stay as they are
[bootstrap.users.jdx]
group = "jdx"
groups = ["tss"]

[bootstrap.files."/etc/systemd/system/ssh-tpm-agent-jdx.service"]
content = """
[Unit]
Description=ssh-tpm-agent for jdx

[Service]
User=jdx
SupplementaryGroups=tss
ExecStart=/usr/bin/ssh-tpm-agent -l /home/jdx/.ssh/tpm-agent.sock
Restart=on-failure

[Install]
WantedBy=multi-user.target
"""
notify = ["ssh-tpm-agent-jdx"]

[bootstrap.services.ssh-tpm-agent-jdx]
state = "running"

Create the TPM-sealed key once with ssh-tpm-keygen, which writes the sealed private key and its .pub file; never copy the sealed file to another machine. Then add the .pub line to the authorized_keys entry of every host it should reach.

Preview and apply ​

sh
mise bootstrap ssh status            # one row per user and one for ~/.ssh/config
mise bootstrap ssh status --json     # the same, with origin details
mise bootstrap ssh status --missing  # exit 1 if anything would change
mise bootstrap ssh apply --dry-run   # list removed keys, the diff, and each write
mise bootstrap ssh apply             # apply after a confirmation prompt
mise bootstrap ssh apply --yes       # apply without prompting

mise bootstrap applies ssh after system files and before services; select it with --only ssh or leave it out with --skip ssh. mise bootstrap status lists the same rows.

MIT LicenseCopyright © 2026jdx.dev