Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Encrypted Key File with cryptsetup
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Installing Gentoo
View previous topic :: View next topic  
Author Message
vokiel
Tux's lil' helper
Tux's lil' helper


Joined: 01 Oct 2004
Posts: 110

PostPosted: Tue May 11, 2021 12:43 am    Post subject: Encrypted Key File with cryptsetup Reply with quote

I was reading https://wiki.gentoo.org/wiki/Custom_Initramfs#Encrypted_keyfile in an effort to avoid gpg completely with a custom initramfs based on https://wiki.gentoo.org/wiki/Custom_Initramfs/Examples#LUKS.2C_LVM.2C_Resume_from_Hibernate.2C_Script_to_Build_the_Initramfs

I'm trying to put this on a USB key mounted either with vfat or ext2.

That seems to fail for me. It throws:

Code:

Requested offset is beyond real size of device whatever/key.luks


when I do:

Code:

sudo mkfs.ext2 /dev/sda1
sudo mount /dev/sda1 whatever/
sudo dd if=/dev/zero of=whatever/key.luks count=2057
sudo cryptsetup --align-payload=1 luksFormat whatever/key.luks
sudo cryptsetup open --type luks whatever/key.luks luksKey


--align-payload is deprecated, so I guess I'm just looking for an update on how to make a key.luks file

Any pointers?
Back to top
View user's profile Send private message
vokiel
Tux's lil' helper
Tux's lil' helper


Joined: 01 Oct 2004
Posts: 110

PostPosted: Tue May 11, 2021 1:51 pm    Post subject: Reply with quote

I'll just encrypt the whole thumb drive and make random keys on an encrypted partition instead of attempting to do an encrypted key file.

It seems I have issues with size. I don't think cryptsetup can be used as described in Encrypting keys anymore.
Back to top
View user's profile Send private message
ocicorp
n00b
n00b


Joined: 11 May 2021
Posts: 1

PostPosted: Tue May 11, 2021 9:25 pm    Post subject: Reply with quote

Hello Vokiel

I have undertaken the encrypted keyfile many times myself for use when maintaining servers which hold devel files that I don't want pilfered :).

I personally follow this pattern:

Code:


sudo dd if=/dev/urandom of=/dev/sdb                     
sudo dd if=/dev/urandom of=~/keyfile count=8192

sudo cfdisk /dev/sdb                                               

sudo mount /dev/sdb1 /mnt/whatever                     
sudo cp ~/keyfile /mnt/whatever/keyfile

sudo cryptsetup luksFormat --key-file /mnt/whatever/keyfile {partition}

sudo cryptsetup luksOpen --key-file /mnt/whatever/keyfile {path_to_encrypted_partition} {mount_point}
               (eg. ... luksOpen --key-file /mnt/whatever/keyfile  /mnt/nvme4b1b1 Gentoo_Root )

And then carry on from there


It is important to note that unless you are booting directly from the USB key, you need to write your grub config to look at your USB key for the partition key.
To alleviate the security consideration, you can either make your USB key look legitimately like a USB linux distro with a grub-option to pivot root to your desktop, or you can just have plain jane Grub sitting there with the correct entries.

Update with your progress
_________________
3700x, 32GB Ram, 980
Algo-trading developer
Back to top
View user's profile Send private message
vokiel
Tux's lil' helper
Tux's lil' helper


Joined: 01 Oct 2004
Posts: 110

PostPosted: Wed May 12, 2021 1:45 pm    Post subject: Reply with quote

Right now I'm looking at the following potential scenario:

1. I have an unencrypted /boot partition and an encrypted LVM one
2. I'll use a USB thumb drive that is also encrypted with the key files on it.
3. I've written my own /init and packaged an initramfs

So I think I'm free to do whatever in there as long as I packaged the binaries needed to first mount the USB drive with its UUID from the GRUB command line and then select the right key file again from the GRUB command line. This is all very loosely based on the example I linked above. I just moved the unencrypted key file from the initramfs to my thumb drive which will be encrypted with a passphrase.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Installing Gentoo All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum