# SSH keys & hardware keys

Keys live in the **Keychain** section of the vault. Hosts and identities reference them by id.

## Generate a key

**Keychain → New key → Generate key**, then pick the type:

| Type        | Notes                                                     |
| ----------- | --------------------------------------------------------- |
| Ed25519     | Recommended: fast, small, supported by all modern servers |
| ECDSA P-256 | For environments that require NIST curves                 |
| ECDSA P-384 | Same, larger curve                                        |
| RSA 4096    | For legacy systems that do not accept the others          |

The private key is generated on your device and stored encrypted in the vault. You may add a passphrase; Vaultport can remember it in the vault or ask on each use.

## Import a key

**Import key** accepts OpenSSH private keys, PEM (PKCS#1 / PKCS#8) and PuTTY `.ppk` files, encrypted or not. Paste the key or choose the file. You can also attach an **OpenSSH certificate** (`…-cert-v01@openssh.com`) to any key so servers that trust your CA accept it.

Importing an `ssh_config` with `IdentityFile` lines imports those keys too — see [Importing](http://vaultport.niessen.dev/guide/importing.md).

## Install a public key on a server

Select a key and choose **Install on host…**. Vaultport connects to the saved host and appends the public key to `~/.ssh/authorized_keys`, creating the file with safe permissions if needed. If the key is already there, nothing changes. **Copy public key** puts the OpenSSH public key on the clipboard for anything else.

## FIDO2 security keys

Security keys such as YubiKeys, SoloKeys or Nitrokeys can hold SSH keys in OpenSSH's FIDO formats `sk-ssh-ed25519@openssh.com` and `sk-ecdsa-sha2-nistp256@openssh.com`, which work with OpenSSH 8.4 and newer on the server.

1. **Keychain → New key → FIDO2 security key**.
2. Insert the key and touch it when it blinks; enter its PIN if it has one.
3. Install the public key on your servers as above.

Every login then requires the physical key (and a touch). The vault only stores the key _handle_; the private key never leaves the token. Security keys work in the desktop apps (Windows, macOS, Linux). New keys are Ed25519 (`ed25519-sk`), which needs a reasonably recent key, for example a YubiKey with firmware 5.2.3 or later.

### Importing keys stored on a security key

Keys created as _resident_ keys (for example with `ssh-keygen -t ed25519-sk -O resident`) live on the security key itself. To use them on a new computer, choose **Keychain → New key → Import from security key**, enter the key's PIN and confirm. Vaultport adds every SSH key it finds (like `ssh-keygen -K`). Keys that are already in your vault are skipped. Keys created with `-O verify-required` keep asking for the PIN at every login.

Key files written by `ssh-keygen -t ed25519-sk`, `-t ecdsa-sk` or `ssh-keygen -K` can also be imported with **Import key**. They contain only the key handle, so they still need the security key at every login.

### Windows

Current versions of Windows (10 version 1903 and later) only let programs running as administrator talk to security keys directly. Vaultport therefore uses the Windows security key dialog instead: Windows asks for the touch and, when needed, the PIN in its own window. This works for USB, NFC and Bluetooth security keys, for both Ed25519 and ECDSA keys, and the signatures are the same as OpenSSH's. Two things differ from macOS and Linux:

- Windows always asks for a touch, even for keys created with `no-touch-required`.
- **Import from security key** needs direct access to the key. Start Vaultport once with **Run as administrator** to import, or run `ssh-keygen -K` and import the key files with **Import key**.

> **Linux**
>
> If no security key is found, make sure your user can access the device's `hidraw` node — see [Installation](http://vaultport.niessen.dev/guide/installation.md#security-keys-and-serial-ports).

## Device keys

A **device key** is created inside your device's secure hardware and can never be exported or copied — not even into the vault:

| Platform   | Backend                                     | Key type                            |
| ---------- | ------------------------------------------- | ----------------------------------- |
| macOS, iOS | Secure Enclave                              | ECDSA P-256 (`ecdsa-sha2-nistp256`) |
| Windows    | Windows Hello                               | RSA-2048 (`rsa-sha2-256`)           |
| Android    | Android Keystore (StrongBox when available) | ECDSA P-256 (`ecdsa-sha2-nistp256`) |
| Linux      | TPM 2.0                                     | ECDSA P-256 (`ecdsa-sha2-nistp256`) |

Every signature asks for Touch ID, Face ID, Windows Hello or, on Android, the system biometric prompt (strong biometrics only). On Linux there is no prompt (see below). Because such a key is bound to one device, register a separate device key per computer or phone, or combine it with another key on your servers. On Android the key is invalidated when you enroll a new fingerprint or face, so you would then need to create and install a new one.

### Linux: TPM 2.0 device keys

On Linux, **Keychain → New key → Device key** makes a P-256 key inside the computer's TPM 2.0 chip (or the firmware TPM, such as AMD fTPM or Intel PTT). Vaultport talks to the kernel's TPM device directly, so you do not need `tpm2-tools` or `tpm2-abrmd`. You need:

- a TPM 2.0 that is enabled in the firmware settings, so that `/dev/tpmrm0` exists (Vaultport falls back to `/dev/tpm0` if the kernel has no resource manager);
- read and write access to that device, usually by joining the `tss` group — see [Installation](http://vaultport.niessen.dev/guide/installation.md#tpm-device-keys);
- a TPM owner hierarchy without an owner password, which is the default on Linux.

The private key never leaves the TPM. The vault stores only the key's public part and a copy of the private part that is encrypted by the TPM itself; only the same TPM can load it. That copy is useless on any other computer, and also on this one after the TPM is cleared (for example by a firmware "Clear TPM" or after some firmware updates). Back up with a second key on your servers.

> **No confirmation on each use**
>
> A TPM has no fingerprint reader or confirmation button, so unlike the other device keys, a TPM key signs **without asking you**. It protects against the key being copied off the machine, not against software on the machine using it: any program running as your user that can open the TPM device and read the unlocked vault can log in with it. If you want a confirmation for every login, use a FIDO2 security key instead.

> **Android support is new**
>
> Android Keystore keys have not yet been verified on many devices. Keep a second way to log in to your servers until you have confirmed the key works on your phone.

## How hardware signatures are checked

Before a signature from a security key or the platform key store is sent to a server, Vaultport verifies it against the key's public key, so a misbehaving device can never make it send a wrong signature. PINs are held in memory that is wiped after use.

## Agent forwarding

When agent forwarding is enabled for a host, Vaultport serves a **read-only, in-process agent** to that server. It can list and use only the keys configured for that host, it cannot add, remove or export keys, and each signature request can require your confirmation. SHA-1 `ssh-rsa` signatures are refused unless legacy algorithms are enabled. Only enable agent forwarding for servers you trust.

When no keys are configured for a host, the desktop apps can also use your **system SSH agent** — see [authentication order](http://vaultport.niessen.dev/concepts/identities-and-keychain.md#authentication-order).
