Storing SSH keys in TPM (for github and other things) | DIMI’s place

DIMI's place

My thoughts on different things

11 September 2023

Storing SSH keys in TPM (for github and other things)

It would be a TLDR version, if you need more info, go to the links section below.

sudo apt install libtpm2-pkcs11-tools libtpm2-pkcs11-1
sudo usermod -a -G tss '$(id -nu)'
tpm2_ptool init
tpm2_ptool addtoken --pid=1 --label=my_key --userpin='' --sopin='recovery_password'
tpm2_ptool addkey --label=my_key --userpin='' --algorithm=rsa2048

From here you should update your ~/.ssh/config:

Host github.com
  HostName github.com
  User git
  PKCS11Provider /usr/lib/x86_64-linux-gnu/libtpm2_pkcs11.so.1
  ForwardAgent yes
  PasswordAuthentication no

And if you want for signatures to be working (local repo example .git/config):

[user]
	signingkey = ~/.ssh/signing/key.pub

[commit]
	gpgsign = true
	verbose = true

[tag]
	gpgsign = true

[gpg]
	format = ssh

[gpg.ssh]
	allowedSignersFile = ~/.config/git/allowed_signers

Sources, lots of them:

Troubleshooting

tags: git - ssh - code sign