{"id":868,"date":"2022-03-28T11:12:35","date_gmt":"2022-03-28T09:12:35","guid":{"rendered":"https:\/\/www.gonscak.sk\/?p=868"},"modified":"2022-03-28T11:12:35","modified_gmt":"2022-03-28T09:12:35","slug":"create-an-encrypted-file-luks-container","status":"publish","type":"post","link":"https:\/\/www.gonscak.sk\/?p=868","title":{"rendered":"Create an encrypted file luks container"},"content":{"rendered":"\n<p>Today, we well create an encrypted file container with some key-file needed to open this container.<\/p>\n\n\n\n<p>At the beginning, we must create a file at size we want. I create a 200GB file with random data:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">dd if=\/dev\/urandom of=\/mnt\/example\/ssd\/private.img bs=2M count=102400\n...\n214748364800 bytes (215 GB, 200 GiB) copied, 1896,49 s, 113 MB\/s<\/pre>\n\n\n\n<p>Now, create a key file, needed for open this file, again with random data. But it can be file of any type &#8211; photo, documents, video, movie&#8230;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">dd if=\/dev\/urandom of=\/mnt\/example\/ssd\/secret.bin bs=1024 count=1 \n...\n1024 bytes (1,0 kB, 1,0 KiB) copied, 0,000155504 s, 6,6 MB\/s<\/pre>\n\n\n\n<p>Now, format this file with luks. Be sure, that  your password is strong. And answer YES to question:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">cryptsetup luksFormat -v \/mnt\/example\/ssd\/private.img \/mnt\/example\/ssd\/secret.bin <\/pre>\n\n\n\n<p>Now, we unlock this file:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo cryptsetup -v luksOpen \/mnt\/example\/ssd\/encrypted.img myEncryptedVolume -\u2013key-file \/mnt\/example\/ssd\/secret.bin <\/pre>\n\n\n\n<p>And check status of this luks container:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo cryptsetup -v status myEncryptedVolume\n\n\/dev\/mapper\/myEncryptedVolume is active.\n  type:    LUKS2\n  cipher:  aes-xts-plain64\n  keysize: 512 bits\n  key location: keyring\n  device:  \/dev\/loop24\n  loop:    \/mnt\/example\/ssd\/encrypted.img\n  sector size:  512\n  offset:  32768 sectors\n  size:    419397632 sectors\n  mode:    read\/write\nCommand successful.\n<\/pre>\n\n\n\n<p>And now, like commands bellow, we close, open and format our file. Then mount it and copy files there \ud83d\ude42<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo cryptsetup luksClose myEncryptedVolume\nsudo cryptsetup -v luksOpen \/mnt\/example\/ssd\/encrypted.img myEncryptedVolume -\u2013key-file \/mnt\/example\/ssd\/secret.bin \nsudo cryptsetup -v status myEncryptedVolume\nsudo mkfs -t ext4 \/dev\/mapper\/myEncryptedVolume\nmkdir \/home\/privates\nsudo mount \/dev\/mapper\/myEncryptedVolume \/home\/privates\n...copy files there...\nsudo umount \/home\/privates\nsudo cryptsetup luksClose myEncryptedVolume<\/pre>\n\n\n\n<p>And that all \ud83d\ude42<\/p>\n ","protected":false},"excerpt":{"rendered":"<p>Today, we well create an encrypted file container with some key-file needed to open this container. At the beginning, we must create a file at size we want. I create a 200GB file with random data: dd if=\/dev\/urandom of=\/mnt\/example\/ssd\/private.img bs=2M count=102400 &#8230; 214748364800 bytes (215 GB, 200 GiB) copied, 1896,49 s, 113 MB\/s Now, create &hellip; <a href=\"https:\/\/www.gonscak.sk\/?p=868\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Create an encrypted file luks container<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[143,98,142,97,60],"class_list":["post-868","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-container","tag-crypt","tag-file","tag-luks","tag-ubuntu"],"_links":{"self":[{"href":"https:\/\/www.gonscak.sk\/index.php?rest_route=\/wp\/v2\/posts\/868","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.gonscak.sk\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.gonscak.sk\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.gonscak.sk\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.gonscak.sk\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=868"}],"version-history":[{"count":4,"href":"https:\/\/www.gonscak.sk\/index.php?rest_route=\/wp\/v2\/posts\/868\/revisions"}],"predecessor-version":[{"id":872,"href":"https:\/\/www.gonscak.sk\/index.php?rest_route=\/wp\/v2\/posts\/868\/revisions\/872"}],"wp:attachment":[{"href":"https:\/\/www.gonscak.sk\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=868"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.gonscak.sk\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=868"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.gonscak.sk\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=868"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}