What is TKM?

Tetra Key Manager manages SSH keys for multi-environment deployments

TKM provides organization-scoped SSH key management with automatic ~/.ssh/config generation. Keys are stored per-org in ~/.ssh// and named by environment and user.

~/.ssh//
  dev_root       # Root key for dev environment
  dev_root.pub
  dev_app        # App user key for dev
  dev_app.pub
  staging_root
  prod_root

Key directory structure

Permission Model

Two-user model: auth_user (login) and work_user (application)

Each environment has two SSH users configured in tetra.toml:

User Type TOML Key Purpose Key Name
Auth User ssh_auth_user Initial SSH login (usually root) _root
Work User ssh_work_user Application deployment user _
[environments.dev]
host = "192.168.1.100"
ssh_auth_user = "root"     # Login as root
ssh_work_user = "app"      # Deploy as app user

tetra.toml environment configuration

Key Lifecycle

Generate, deploy, rotate, revoke

  1. init - Create ~/.ssh// directory
  2. generate - Create ED25519 key pairs, update ~/.ssh/config
  3. deploy - Push public keys to remote authorized_keys
  4. test - Verify SSH connectivity
  5. rotate - Revoke old + generate new + deploy (atomic rotation)
  6. revoke - Archive keys with timestamp, remove SSH config

Info Commands

Status, diagnostics, and key information

Key Operations

Generate, deploy, and manage SSH keys

SSH Config

Manage ~/.ssh/config entries

# tkm: myorg dev
Match Host 192.168.1.100 User root
    IdentityFile ~/.ssh/myorg/dev_root

Match Host 192.168.1.100 User app
    IdentityFile ~/.ssh/myorg/dev_app

Generated SSH config (Match blocks by hostname + user)

Remote Key Management

Manage authorized_keys on remote servers

Remote commands support flags: -f, --force (skip confirmation), -n, --dry-run (preview changes)

Initial Setup

First-time key setup for a new organization

# 1. Switch to organization
org switch myorg

# 2. Initialize key directory
tkm init
# Created: ~/.ssh/myorg/

# 3. Generate all keys
tkm gen all
# Generates: dev_root, dev_app, staging_root, prod_root
# Updates: ~/.ssh/config with Match blocks

# 4. Deploy keys (needs initial access)
tkm deploy all --key ~/.ssh/id_rsa
# Pushes public keys to authorized_keys

# 5. Verify
tkm test
# Tests SSH connectivity to all environments

Key Rotation

Rotate compromised or expired keys

# Full rotation (revoke + generate + deploy)
tkm rotate dev

# Manual rotation steps:
tkm revoke dev         # Archive old keys
tkm gen dev            # Generate new keys
tkm deploy dev         # Deploy to server

# Revoked keys are archived:
# ~/.ssh/myorg/dev_root.revoked.20241206_143022

Audit & Sync

Keep local and remote keys in sync

# Audit: show known vs unknown keys
tkm remote audit dev root
# [1] [KNOWN]   tkm_dev_root
# [2] [UNKNOWN] user@laptop

# Diff: show what needs to change
tkm remote diff dev root
# Present: dev_root (SHA256:abc...)
# Missing: (none)
# Extra: user@laptop (SHA256:xyz...)

# Sync: make remote match local (dry-run first)
tkm remote sync -n dev root
tkm remote sync dev root

org Module

TKM reads environment config from org module

TKM depends on the org module for organization and environment configuration. The active organization determines where keys are stored.

org Function TKM Usage
org_active() Get current org name for key directory
org_env_names() List environments from tetra.toml
_org_get_host(env) Get SSH hostname for environment
_org_get_user(env) Get auth_user for SSH login
_org_get_work_user(env) Get work_user for key naming

deploy Module

Deploy uses tkm for SSH connectivity

The deploy module uses TKM-managed keys for remote operations. After tkm deploy, deployment commands work automatically:

# SSH uses tkm keys automatically
ssh root@$dev      # Uses ~/.ssh/myorg/dev_root
ssh app@$dev       # Uses ~/.ssh/myorg/dev_app

# Deploy commands work
deploy push myapp dev
deploy exec dev "systemctl restart myapp"

tetra.toml Configuration

Environment configuration for SSH

[org]
name = "myorg"

[environments.dev]
host = "dev.example.com"
ssh_auth_user = "root"
ssh_work_user = "app"

[environments.staging]
host = "staging.example.com"
ssh_auth_user = "root"
ssh_work_user = "deploy"

[environments.prod]
host = "prod.example.com"
ssh_auth_user = "root"
ssh_work_user = "app"

Full tetra.toml example with SSH configuration

Key Security

Security features and best practices

Lifecycle Security

Safe key rotation and revocation

Auditing

Track and verify key access

Regular auditing helps detect unauthorized keys:

# Check all environments
for env in dev staging prod; do
  echo "=== $env ==="
  tkm remote audit $env root
done

# Remove unknown keys
tkm remote clean dev root 'unknown_*'
tkm remote sync dev root
Design Tokens ×
Theme Switcher
Theme Metadata
Colors
Background
--bg-primary
#1a1a2e
--bg-secondary
#16213e
--bg-tertiary
#0d1b2a
Text
--text-title
#eaeaea
--text-primary
#c0c0d0
--text-secondary
#8a8aa0
--text-code
#ff6b6b
Accent
--accent-primary
#e94560
--accent-secondary
#3b82c4
Status
--success
#3fb950
--warning
#d29922
--error
#f85149
Border
--border
#2a2a4a
Layout
Section Style
Sharp 8px Round