Files
ShellBook/templates/workspace/notebooks/ssh-key.md
T
Florian Schmidt 91ac1df8a5 feat(templates): add starter runbook workspace (#5)
Document the notebook format and provide SSH-key, hardening-check, and package-install examples with inventory and credential exclusions.
2026-11-16 00:04:45 +01:00

2.0 KiB

title, params
title params
New server SSH key
host user keyname
type required label
host true Target server
type required default label
name true admin Login user
type default
name id_ed25519_{{host}}

New server SSH key

Creates a key pair for {{user}} on {{host}} and authorizes it. The host needs OpenSSH and passwordless sudo. The private key stays local to ShellBook until downloaded; only the public key is uploaded.

id {{user}}
sshd -T | grep -qx 'passwordauthentication no'
ssh-keygen -q -t ed25519 -N '' -C {{user}}@{{host}} -f {{keyname}}

Each execution generates a fresh pair in its own workdir. Rerunning this step intentionally creates a new key; it does not overwrite a key from an earlier run.

home=$(getent passwd {{user}} | cut -d: -f6)
test -n "$home"
group=$(id -gn {{user}})
install -d -m 700 -o {{user}} -g "$group" "$home/.ssh"
touch "$home/.ssh/authorized_keys"
key=$(cat /tmp/shellbook-new-key.pub)
if ! grep -qxF -- "$key" "$home/.ssh/authorized_keys"; then
  printf '%s\n' "$key" >> "$home/.ssh/authorized_keys"
fi
chown {{user}}:"$group" "$home/.ssh/authorized_keys"
chmod 600 "$home/.ssh/authorized_keys"
rm -f /tmp/shellbook-new-key.pub

:::after{step=keygen} Download the private key once and save it securely:

  • Linux: ~/.ssh/{{keyname}}, then chmod 600 ~/.ssh/{{keyname}}.
  • Windows: C:\Users\<you>\.ssh\{{keyname}}, accessible only to your user.

Keep the public artifact available for the authorization step. Never commit the private key. :::

:::after{step=authorize failed} Inspect the output and confirm the account and sudo access before retrying. :::