Skip to main content

Module ssh_key

Module ssh_key 

Source
Expand description

Generating an SSH key pair, in process.

Why not shell out to ssh-keygen. It is not reliably installed (Windows ships the OpenSSH client as an optional feature that managed images often have off, and the binary on PATH may be Git for Windows’, WSL’s or none) and it is interactive by default. ssh-key produces the same OpenSSH-format files with no process and no prompt.

Ed25519 by default. Short, fast, and accepted by both GitHub and GitLab. ssh.key_type can ask for RSA (4096 bits) or ECDSA (NIST P-256) instead, see KeyType.

No passphrase. A generated key is written unencrypted, as ssh-keygen -N "" would, because the point is a key an agent-less git fetch can use unattended. The file permissions below are what protects it; the docstring on generate_and_write says so.

Structs§

GeneratedKey
A freshly generated pair. The private half is held only long enough to be written; nothing in this crate sends it anywhere.

Enums§

KeyType
The kind of key to generate (ssh.key_type).

Functions§

default_key_path
The default key path, ~/.ssh/id_ed25519, which is where ssh looks without being told.
default_key_title
A default title for an uploaded key: the machine’s name, so a user with keys from three machines can tell them apart on the host’s settings page.
fingerprint_of
SHA256:... of an OpenSSH public-key line, or None when it is not one.
generate_and_write
Generates an Ed25519 pair (see generate_typed_and_write for the others) and writes it to path and path.pub.
generate_typed_and_write
generate_and_write for a chosen KeyType.
profile_key_path
The private-key path a profile’s generated key gets inside ssh_dir: gitpoulpi_<profile id>_ed25519. Per profile so two accounts on one host never share (or overwrite) a key.
profile_key_title
The title a profile’s key gets when the user does not type one: GitPoulpi <host> <YYYY-MM-DD>.
same_public_key
Whether two public-key lines are the same key (the comment, which hosts rewrite, is ignored).
ssh_command_for_key
The core.sshCommand value that pins one private key for a repository (ADR-0008): ssh -i "<key>" -o IdentitiesOnly=yes. Backslashes become forward slashes, which git’s sh accepts on Windows too.
ssh_dir
~/.ssh, where ssh looks for keys.