Skip to main content

SSH Agent

What​

Display whether an ssh-agent is running and which SSH keys are loaded. Give your keys friendly names with mapped_keys.

Sample Configuration​

− ▢ ×  personal work@laptop _ ohmyposh.dev − ▢ ×  personal work@laptop _ ohmyposh.dev

Options​

NameTypeDefaultDescription
key_templatestring{{ or .Alias .Comment }}template for each key
key_separatorstring" "text between keys
mapped_keysmap[string]stringfingerprint-to-alias map

Use the SHA256 fingerprint shown by ssh-add -l as the map key. Its value is available as .Alias in key_template; see Key Properties for the available properties.

Template (info)​

default template
{{ if .Running }} {{ "\uf43d" }} {{ .Count }} {{ end }}

Properties​

NameTypeDescription
.Runningbooleanwhether an ssh-agent is reachable
.Countintthe number of keys loaded into the ssh-agent
.Keysstringthe loaded keys rendered with key_template, joined by key_separator
.UnmappedCountintnumber of loaded keys without an entry in mapped_keys

Keys for which key_template renders nothing are left out of .Keys, but still count towards .Count and .UnmappedCount.

Key Properties​

Available in key_template:

NameTypeDescription
.Aliasstringthe mapped_keys value for this key's fingerprint, if any
.Bitsintthe key size in bits
.Commentstringthe key comment, usually user@host or the key file path
.Fingerprintstringthe SHA256 fingerprint, e.g. SHA256:Lx2fJq7k...
.Typestringthe key type, e.g. ED25519 or RSA

Examples​

Show a hint when no agent is running:

{{ if .Running }} {{ "\uf43d" }} {{ .Count }} {{ else }} no agent {{ end }}

List the loaded keys, with key_template set to {{ .Comment }} ({{ .Type }}):

{{ if .Running }} {{ "\uf43d" }} {{ .Keys }} {{ end }}

Show only mapped keys and the number of remaining keys, e.g. work, personal +3, with key_template set to {{ .Alias }} and key_separator set to ", ":

{{ if .Running }} {{ "\uf43d" }} {{ .Keys }}{{ if gt .UnmappedCount 0 }} +{{ .UnmappedCount }}{{ end }} {{ end }}