Use any of the available guides for details, here’s just the short version
(the efitools README is also quite useful).
Enable Setup Mode in your UEFI firmware (delete all existing keys) to add
your custom keys. Install efitools and sbsigntool on your system.
openssl req -new -x509 -newkey rsa:2048 -subj "/CN=PK/" -keyout PK.key -out PK.crt -days 7300 -nodes -sha256
openssl req -new -x509 -newkey rsa:2048 -subj "/CN=KEK/" -keyout KEK.key -out KEK.crt -days 7300 -nodes -sha256
openssl req -new -x509 -newkey rsa:2048 -subj "/CN=db/" -keyout db.key -out db.crt -days 7300 -nodes -sha256
Prepare installation in EFI:
cert-to-efi-sig-list PK.crt PK.esl
sign-efi-sig-list -k PK.key -c PK.crt PK PK.esl PK.auth
cert-to-efi-sig-list KEK.crt KEK.esl
sign-efi-sig-list -k PK.key -c PK.crt KEK KEK.esl KEK.auth
cert-to-efi-sig-list db.crt db.esl
sign-efi-sig-list -k KEK.key -c KEK.crt db db.esl db.auth
Install keys into EFI (PK last as it will enable Custom Mode locking out
further unsigned changes):
efi-updatevar -f db.auth db
efi-updatevar -f KEK.auth KEK
efi-updatevar -f PK.auth PK
The EFI variables may be immutable (i-flag in lsattr output) in recent
kernels (e.g. 4.5.4). Use chattr -i to make them mutable again if you can’t
update the variables with the commands above:
chattr -i /sys/firmware/efi/efivars/{PK,KEK,db,dbx}-*
From now on only EFI binaries signed with any db key can be loaded. To sign
a binary use:
sbsign --key /path/to/db.key --cert /path/to/db.crt /path/to/efi
Then use the .signed file to boot.