SSH Key Input

Catches a private SSH key pasted where a public key belongs, plus weak, truncated or malformed public keys, before they're saved.

StopsPrivate SSH key pasted where a public key belongs

Installation

pnpm dlx shadcn@latest add https://bollard-ui.vercel.app/r/ssh-key-input.json

The files land in your project. They're yours to edit.

Usage

ssh-key-input-usage.tsx
import { decodeBase64, encodeBase64, SshKeyInput } from "@/components/ui/ssh-key-input"

<SshKeyInput value={value} onValueChange={setValue} existing={[{ key: LAPTOP, label: "MacBook (added 3 Sep)" }]} />

What it catches

  • A private key pasted instead of a public one, with rotate advice and the public half extracted when possible
  • DSA keys and RSA keys under minRsaBits (default 2048; 3072 recommended)
  • Keys wrapped across lines or cut off
  • Missing or mismatched type prefix
  • RFC 4716 (SSH2) export format, converted
  • A key already on the account

Props

SshKeyInput props
PropTypeDefault
value

Controlled text.

string—
defaultValue

Initial text when uncontrolled.

string""
onValueChange

Called with the new text on every edit or fix.

(value: string) => void—
onAnalysisChange

Called whenever the reading changes, so a form can enable its Add button only for a clean key.

(analysis: SshKeyAnalysis) => void—
existing

Keys already on the account (line or "SHA256:…" fingerprint, with a label). A repeat is flagged by name.

ExistingSshKey[]NONE
minRsaBits

RSA keys below this are rejected. Default 2048.

number2048
recommendedRsaBits

RSA keys below this get a softer warning. Default 3072, GitHub's minimum for new keys.

number3072
label

Visible label; shorthand for `messages.label`.

string—
messages

Every visible string. `{detail}`, `{bits}`, `{min}`, `{recommended}`, `{name}`, `{count}` are filled in.

Partial<SshKeyInputMessages>—

* required. Also accepts the native props of <textarea> (className, aria-*, data-*…), passed through to it.

Accessibility

  • Visible <label>; aria-invalid on blocking issues; hint and report via aria-describedby
  • Private-key warning uses role=alert; summary is role=status
  • After a fix, focus moves to the next fix or back to the field

Only what the source does. Test with your own screen reader and content before shipping.

Limitations

This is a UX guard rail. Enforce on the server: Re-validate the key server-side, reject private keys and weak types, and never log submitted key material.

  • Checks key format and size, not who owns the key
  • A pasted private key has already been exposed to this page; advise rotation regardless
  • Certificate and hardware-key (sk-) variants may be reported generically

What it stops

Private SSH key pasted where a public key belongs

Also known as

ssh key · public key · id_ed25519.pub · authorized_keys · deploy key · github ssh · fingerprint · ssh-keygen

Dependencies

Pairs well with