Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
S

ssh-tpm-agent

> AI 编程
Open source

:computer: :key: ssh-agent for TPMs

729 stars0 likes0 views
WebsiteGitHub

About

:computer: :key: ssh-agent for TPMs

SSH agent for TPM

ssh-tpm-agent is a ssh-agent compatible agent that allows keys to be created by the Trusted Platform Module (TPM) for authentication towards ssh servers.

TPM sealed keys are private keys created inside the Trusted Platform Module (TPM) and sealed in .tpm suffixed files. They are bound to the hardware they are produced on and can't be transferred to other machines.

This allows you to utilize a native client instead of having to side load existing PKCS11 libraries into the ssh-agent and/or ssh client.

The project uses TPM 2.0 Key Files implemented through the go-tpm-keyfiles project.

Features

  • A working ssh-agent.
  • Create shielded ssh keys on the TPM.
  • Creation of remotely wrapped SSH keys for import.
  • PIN support, dictionary attack protection from the TPM allows you to use low entropy PINs instead of passphrases.
  • TPM session encryption.
  • Proxy support towards other ssh-agent servers for fallbacks.

SWTPM support

Instead of utilizing the TPM directly, you can use --swtpm or export SSH_TPM_AGENT_SWTPM=1 to create an identity backed by swtpm which will be stored under /var/tmp/ssh-tpm-agent.

Note that swtpm provides no security properties and should only be used for testing.

Installation

The simplest way of installing this plugin is by running the following:

go install github.com/foxboron/ssh-tpm-agent/cmd/...@latest

Alternatively download the pre-built binaries.

Usage

…

Note: For ssh-tpm-agent you can specify the TPM owner password using the command line flags -o or --owner-password, which are preferred. Alternatively, you can use the environment variable SSH_TPM_AGENT_OWNER_PASSWORD.

Import existing key

Useful if you want to back up the key to a remote secure storage while using the key day-to-day from the TPM.

…

Install user service

Socket activated services allow you to start ssh-tpm-agent when it's needed by your system.

# Using the socket
$ ssh-tpm-agent --install-user-units
Installed /home/fox/.config/systemd/user/ssh-tpm-agent.socket
Installed /home/fox/.config/systemd/user/ssh-tpm-agent.service
Enable with: systemctl --user enable --now ssh-tpm-agent.socket

$ systemctl --user enable --now ssh-tpm-agent.socket

$ export SSH_AUTH_SOCK="$(ssh-tpm-agent --print-socket)"

$ ssh [email protected]

Proxy support

…

ssh-tpm-add

$ ssh-tpm-agent --no-load &
2023/08/12 13:40:50 Listening on /run/user/1000/ssh-tpm-agent.sock

$ export SSH_AUTH_SOCK="$(ssh-tpm-agent --print-socket)"

$ ssh-add -L
The agent has no identities.

$ ssh-tpm-add $HOME/.ssh/id_ecdsa.tpm
Identity added: /home/user/.ssh/id_ecdsa.tpm

$ ssh-add -L
ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBJCxqisGa9IUNh4Ik3kwihrDouxP7S5Oun2hnzTvFwktszaibJruKLJMxHqVYnNwKD9DegCNwUN1qXCI/UOwaSY= test

Create and Wrap private key for client machine on remote server

On the client side create one a primary key under an hierarchy. This example will use the owner hierarchy with an SRK.

The output file srk.pem needs to be transferred to the remote end which creates the key. This could be done as part of client provisioning.

$ tpm2_createprimary -C o -G ecc -g sha256 -c prim.ctx -a 'restricted|decrypt|fixedtpm|fixedparent|sensitivedataorigin|userwithauth|noda' -f pem -o srk.pem

On the remote end we create a p256 ssh key, with no password, and wrap it with ssh-tpm-keygen with the srk.pem from the client side.

$ ssh-keygen -t ecdsa -b 256 -N "" -f ./ecdsa.key
# OR with openssl
$ openssl genpkey -algorithm EC -pkeyopt ec_paramgen_curve:prime256v1 -out ecdsa.key

# Wrap with ssh-tpm-keygen
$ ssh-tpm-keygen --wrap-with srk.pub --wrap ecdsa.key -f wrapped_id_ecdsa

On the client side we can unwrap wrapped_id_ecdsa to a loadable key.

$ ssh-tpm-keygen --import ./wrapped_id_ecdsa.tpm -f id_ecdsa.tpm
$ ssh-tpm-add id_ecdsa.tpm

ssh-tpm-hostkey

ssh-tpm-agent also supports storing host keys inside the TPM.

…

ssh-config

It is possible to use the public keys created by ssh-tpm-keygen inside ssh configurations.

The below example uses ssh-tpm-agent and also passes the public key to ensure not all identities are leaked from the agent.

sshconfig
Host example.com
    IdentityAgent $SSH_AUTH_SOCK

Host *
    IdentityAgent /run/user/1000/ssh-tpm-agent.sock
    IdentityFile ~/.ssh/id_ecdsa.pub

License

Licensed under the MIT license. See LICENSE or https://opensource.org/licenses/MIT

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

Gogo-tpmgolangsecurityssh

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
CategoryAI 编程
PricingOpen source

> Related tools

G
GitHub Copilot
GitHub 官方 AI 编程助手,覆盖补全、Chat 与 Agent 模式。
C
Cursor
AI 原生代码编辑器,对话改代码、多文件 Agent 与规则体系是其核心。
S
skills
Skills for Real Engineers. Straight from my .agents directory.