First attempt #
- Connect trezor to your machine;
- Go to trezor.io/start;
- Download the AppImage and set it as executable
chmod +x downloaded-trezor.AppImage
; - Run the app;
- App is saying that things aren't properly configured :(
Installing the udev rules #
Either through an aur package or install them manually:
- AUR: https://aur.archlinux.org/packages/trezor-udev ;
- Manually
- Copy https://raw.githubusercontent.com/trezor/trezor-common/master/udev/51-trezor.rules into
/usr/lib/udev/rules.d/51-trezor.rules
- Reload udev rules:
sudo udevadm trigger --action=change
sudo udevadm control --reload-rules
- Copy https://raw.githubusercontent.com/trezor/trezor-common/master/udev/51-trezor.rules into
Trying the app again #
- Plug your trezor on your machine. Make sure the USB-C is correctly plugged into your trezor, you need to make a bit of force for it to snap into place;
- Run the app;
- Analytics prompt:
- Whatever you want, I disabled it because "How you use the Suit" is too broad.
- Install the firmware;
- Your trezor will display the installation process with a pie/round loading bar;
- After the installation is done, the device will restart.
- Setup your hardware. At time of writing these are the steps, they might be different for you, just follow the on-screen instructions:
- Setup your seed;
- Setup your PIN;
- Setup your crypto;
- Done.
2FA #
Gitlab #
- Login to gitlab.com;
- Got to User > Edit profile/Preferences > Account;
- Two-factor authentication > Manage;
- Register WebAuthn Device;
- Accept the trezor prompt;
- Sign out;
- Login again;
- Accept the trezor prompt;
- Done!
Github #
- Login to github.com;
- Got to settings > Password and authentication > Two-factor authentication > Security keys > Add;
- Go through your existing 2fa flow;
- Go to Security keys > Register new security key;
- Accept your trezor prompt;
- Sign out;
- Login again;
- Click "Use security key" > "use this method for future logins";
- Click "User security key" green button;
- Accept the trezor prompt;
- Done!
Passwordless login #
Placeholder:
HOSTNAME
is the hostname of the machine, you can get this by runningcat /etc/hostname
;YOU_USERNAME
is the username of the user you are logged in as, you can get this by runningwhoami
;
Initial Setup #
- https://wiki.archlinux.org/title/Universal_2nd_Factor#Authentication_for_Arch_Linux
- Install the require packages:
sudo pacman -Syu pam-u2f
; - Create the directory for your keys:
mkdir ~/.config/Trezor
; - Setup your key:
pamu2fcfg -o pam://HOSTNAME -i pam://HOSTNAME > ~/.config/Trezor/u2f_keys
:- You could potentially save this on a different path, but I'll follow the arch guide for now;
- I'm not sure, but I'm guessing the hostname here doesn't really matter and maybe you can use whatever you want, as long as you follow the same name thought the configs. Maybe it's even better to have different keys for different pam modules?
- Install the require packages:
PAM #
- Edit your pam config for sudo:
- Open
/etc/pam.d/sudo
; - Add the following line:
auth sufficient pam_u2f.so cue origin=pam://HOSTNAME appid=pam://HOSTNAME authfile=/home/YOUR_USERAME/.config/Trezor/u2f_keys
.
- Save.
- Open
- Open a new terminal and run a sudo command;
- Done!
Login on tty #
- Edit your pam config for local login:
- Open
/etc/pam.d/system-local-login
; - Add the following line:
auth sufficient pam_u2f.so nouserok origin=pam://hostname appid=pam://hostname authfile=/home/YOUR_USERAME/.config/Trezor/u2f_keys
.
- Save.
- Open
- Change to a different tty and login;
- Done!
LUKS unlock #
Placeholders:
PARTITION
: path of your encrypted partition (ex: /dev/nvme0n1p1)PARTITION_UUID
: the uuid of your encrypted partition (ex: 3821f146-df8a-4e90-9de4-121c98363930)DEC_PARITION_NAME
: the name of the decrypted parition (ex:cryptroot
)GRUB_CFG_PATH
: The path to where yourgrub.cfg
is located.
There are a ton of guides online on how to do this. This guide in specific will focus on existing setups using LUKS on the root partition with a unencrypted boot partition, with no LVM or any additional layers of volume abstraction.
Existing setup before applying the passwordless configuration #
mkinitcpio
modules
base udev autodetect keyboard keymap consolefont modconf block encrypt filesystems fsck
- Tool used to generate RAM disk images
- Grub params
cryptdevice=UUID=MY_PARTITION_UUID:cryptroot root=/dev/mapper/cryptroot
/etc/crypttab
(empty)
lsblk
after boot
$ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
nvme0n1 259:0 0 400.4G 0 disk
├─nvme0n1p1 259:4 0 200G 0 part
│ └─cryptroot 254:0 0 200G 0 crypt /
└─nvme0n1p2 259:5 0 350M 0 part /boot
cryptsetup luksDump /dev/nvme0n1p1
LUKS header information
Version: 2
Epoch: 7
Metadata area: xxx [bytes]
Keyslots area: xxx [bytes]
UUID: MY_PARTITION_UUID
Label: (no label)
Subsystem: (no subsystem)
Flags: (no flags)
Data segments:
0: crypt
offset: xxx [bytes]
length: (whole device)
cipher: xxx
sector: xxx [bytes]
Keyslots:
0: luks2
Key: xxx bits
Priority: xxx
Cipher: xxx
Cipher key: xxx bits
PBKDF: argon2id
Time cost: x
Memory: xxx
Threads: x
Salt: xxx
AF stripes: xxx
AF hash: sha256
Area offset:xxx [bytes]
Area length:xxx [bytes]
Digest ID: 0
Tokens:
Digests:
0: pbkdf2
Hash: sha256
Iterations: xxx
Salt: xxx
Digest: xxx
Applying the passwordless configuration #
Before making any changes, make sure you have backed up your LUKS header and know how to restore it. Search for luks restore luksHeaderBackup
keywords online for more info.
Also, make sure you backup your existing /etc/mkinitcpio.conf
and /etc/default/grub
. If you mess something up, you can boot into a live arch linux usb and recover from there.
- Connect and unlock your trezor;
- Enroll your trezor into luks:
systemd-cryptenroll --fido2-device=auto PARTITION
.
- (optional) Make a recovery key:
systemd-cryptenroll --recovery-key PARTITION
.
- Change the necessary modules in
/etc/mkinitcpio.conf
:- In
HOOKS
:- Replace
udev
withsystemd
; - Replace
encrypt
withsd-encrypt
.
- Replace
- In
- Change
/etc/default/grub
with the necessary kernel options:- Remove luks configuration from
GRUB_CMDLINE_LINUX_DEFAULT
and/orGRUB_CMDLINE_LINUX
, things like:cryptdevice=UUID=PARTITION_UUID:cryptroot root=/dev/mapper/DEC_PARITION_NAME
.
- Remove luks configuration from
- Update
/etc/crypttab.initramfs
with the new config line (create the file if it doesn't exist):DEC_PARITION_NAME UUID=PARTITION_UUID none luks,discard,fido2-device=auto,keyfile-timeout=30
- Additional info about each column:
DEC_PARITION_NAME
: the rootname you had in/etc/default/grub
;PARTITION_UUID
: the uuid of the encrypted partition you had in/etc/default/grub
;none
: the password, we are going to use trezor in this case;- list of options.
- Additional info about each column:
- Regenerate your grub config and mkinitcpio images:
- grub:
grub-mkconfig -o GRUB_CFG_PATH
; - mkinitcpio:
mkinitcpio -P
.
- grub:
- Reboot;
- Done!
Setup after applying the passwordless configuration #
- mkinitcpio modules
base systemd autodetect keyboard keymap consolefont modconf block sd-encrypt filesystems fsck
- Grub luks params
(none)
- /etc/crypttab
DEC_PARITION_NAME UUID=PARTITION_UUID none luks,discard,fido2-device=auto,keyfile-timeout=30
- lsblk after login
(no difference)
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
nvme0n1 259:0 0 400.4G 0 disk
├─nvme0n1p1 259:4 0 200G 0 part
│ └─cryptroot 254:0 0 200G 0 crypt /
└─nvme0n1p2 259:5 0 350M 0 part /boot
cryptsetup luksDump /dev/nvme0n1p1
(only showing the difference)
Tokens:
0: systemd-fido2
fido2-credential:
xxx
fido2-salt: xxx
fido2-rp: io.systemd.cryptsetup
fido2-clientPin-required:
false
fido2-up-required:
true
fido2-uv-required:
false
Keyslot: 1
1: systemd-recovery
Keyslot: 2
Props #
- https://bbs.archlinux.org/viewtopic.php?id=265134
- https://www.guyrutenberg.com/2022/02/17/unlock-luks-volume-with-a-yubikey/
- https://0pointer.net/blog/unlocking-luks2-volumes-with-tpm2-fido2-pkcs11-security-hardware-on-systemd-248.html
SSH keys for git #
Placeholder:
EMAIL
: the email you want to use for your ssh keyPATH_TO_PRIVATE
: the to the the generated private key
- Generate your new ssh key pair:
ssh-keygen -t ecdsa-sk -O application=ssh:EMAIL
;- Type a password if you want;
- Choose the path to your key pair (henceforth referred as
PATH_TO_PRIVATE
for the path of the private key).
- Add your public key to your git host, the public key can be found alongside
PATH_TO_PRIVATE
, it should be the same file name with a.pub
extension; - Modify your existing local entry for your git host in
~/.ssh/config
:- Change or add
IdentityFile PATH_TO_PRIVATE
.
- Change or add
- Do a git command that requires authentication, like
git fetch
; - Done!
Props #
GPG for git #
Placeholder:
GPG_KEY_ID
: The gpg key ID that trezor generated.
- Install trezor agent
pip3 install trezor_agent
; - Initialize trezor gpg
trezor-gpg init "Username <your@email.com>" -v
:- Type a passphrase if you want.
- List your newly created key:
GNUPGHOME=~/.gnupg/trezor gpg2 --list-secret-keys --keyid-format=long
:- Copy the key ID from
sec nistp256/GPG_KEY_ID 1970-01-01 [SC]
; - Export it with
GNUPGHOME=~/.gnupg/trezor gpg2 --armor --export GPG_KEY_ID
- Past that key into your git hoster.
- From now on, you'll have to tell git to use trezor gpg folder instead of the default one. This can be a bit messy because, as of the time of writing, you cannot mix trezor keys and other keys in the same folder as it will throw errors. Since we only want to use these keys in git for now, we can alias
git
to user trezor's gpg folder:- Add the following to
.bash_aliases
:alias git='GNUPGHOME=~/.gnupg/trezor git'
.
- Add the following to
- Update git to use the new gpg key:
git config --global user.signingkey GPG_KEY_ID
.
- Refresh your terminal;
- Commit something;
- Done.
Using multiple GPG identities #
From what I could understand, each folder inside ~/.gnupg/*
generated by trezor can only hold one identity, so if you want to use multiple identities, you'll have to use different paths:
- Initialize trezor gpg with a different home path
trezor-gpg init "New Username <your@newemail.com>" --homedir ~/.gnupg/new-identity
:- Type a passphrase if you want.
- Follow the steps from the previous section to add the new key to your git hoster, keep in mind that you'll have to use the path to your new identity:
GNUPGHOME=~/.gnupg/new-identity gpg2 --list-secret-keys --keyid-format=long
;
- Follow the steps above to add the new identity key to git, overwriting the kye locally for each repo if needed:
- setting the key on the current repo only:
git config user.signingkey GPG_KEY_ID
.
- setting the key on the current repo only:
Git in vscode #
Vscode ignores aliases and uses a direct path to the git binary, meaning that the alias we created before is not used. To go around this, we'll have to point vscode to our own git that uses trezor's gpg folder.
- Create an sh file anywhere on your system with the following contents:
1#!/bin/sh 2 3GNUPGHOME=~/.gnupg/trezor git "$@"
- Make it executable:
chmod +x PATH_TO_FILE
; - Add the following to your global vscode settings.json file:
1"git.path": "PATH_TO_FILE",
- Restart vscode;
- Done!
You can optionally change the git alias we created before to point to the sh file we created above.
If you want to use multiple identities, you'll have to create a new sh file for each identity, pointing to the correct gpg home folder and change the vscode setting above every time you want to use a different identity.
The path to git cannot be changed in each project due to a vscode limitation #98517, a feature request was opened #163116.
Another option is to not use vscode to commit, but use the terminal (or any other application that respects aliases) instead.
Props #
Addendum #
- Added a section on how to use multiple GPG identities;
- Fixed usage of multiple gpg identities in vscode;
- Added steps to use new gpg keys in git.