{{ page.description }}

s/$USER/user name/):
+
+{% highlight bash %}
+mv /home/{$USER,$USER-org}
+mkdir /home/$USER
+chmod 700 /home/$USER
+chown $USER:users /home/$USER
+{% endhighlight %}
+
+ The widespread solution in the Internet is to use automatic utilities to do it. However in our case they are not suitable, since we need to import key / password signature, which is not possible in this case.
+ +The encryption can be done by the following command (lol):
+ +{% highlight bash %} +mount -t ecryptfs /home/$USER /home/$USER +{% endhighlight %} + +While process it asks some question (I suggest to do first mounting in the interactive mode). The answers may be like following (see the comments), +please note that if you change something, it will be changed in some lines below too:
+ +{% highlight bash %} +# key or certificate. The second one is more reliable while you don't lose it %) +Select key type to use for newly created files: + 1) passphrase + 2) openssl +Selection: 1 +# password +Passphrase: +# cipher, select default +Select cipher: + 1) aes: blocksize = 16; min keysize = 16; max keysize = 32 + 2) blowfish: blocksize = 8; min keysize = 16; max keysize = 56 + 3) des3_ede: blocksize = 8; min keysize = 24; max keysize = 24 + 4) twofish: blocksize = 16; min keysize = 16; max keysize = 32 + 5) cast6: blocksize = 16; min keysize = 16; max keysize = 32 + 6) cast5: blocksize = 8; min keysize = 5; max keysize = 16 +Selection [aes]: 1 +# key size, select default +Select key bytes: + 1) 16 + 2) 32 + 3) 24 +Selection [16]: 1 +# enable reading/writing to the non-encrypted files +Enable plaintext passthrough (y/n) [n]: n +# enable filename encryption +Enable filename encryption (y/n) [n]: y +Filename Encryption Key (FNEK) Signature [XXXXX]: +# toolongdontread +Attempting to mount with the following options: + ecryptfs_unlink_sigs + ecryptfs_fnek_sig=XXXXX + ecryptfs_key_bytes=16 + ecryptfs_cipher=aes + ecryptfs_sig=XXXXX +WARNING: Based on the contents of [/root/.ecryptfs/sig-cache.txt], +it looks like you have never mounted with this key +before. This could mean that you have typed your +passphrase wrong. + +# accept, quit +Would you like to proceed with the mount (yes/no)? : yes +Would you like to append sig [XXXXX] to +[/root/.ecryptfs/sig-cache.txt] +in order to avoid this warning in the future (yes/no)? : yes +Successfully appended new sig to user sig cache file +Mounted eCryptfs +{% endhighlight %} + +Then copy files from home directory to encrypted one:
+ +{% highlight bash %} +cp -a /home/$USER-org/. /home/$USER +{% endhighlight %} + +Create file on flash card (I've used microSD) with the following text (you should insert your password):
+ +{% highlight bash %} +passphrase_passwd=someverystronguniqpassword +{% endhighlight %} + +Add card automount (mount point is /mnt/key) to fstab with option ro, for example:
Let's configure home directory mounting. The mount options can be found in the following output:
+ +{% highlight bash %} +mount | grep ecryptfs +{% endhighlight %} + +I should note that there are not all options there, you need add key, no_sig_cache, ecryptfs_passthrough too. Thus systemd mount-unit should be like the following (if you are systemd-hater you can write the own daemon, because it doesn't work over fstab without modification (see below)).
XXXXX should be replaced to signature from options with which directory are currently mounting. Also you need to insert user name and edit path to file with password (and unit name) if it is needed. Autoload:
Here is a service to unmount flash card when it will be unneeded:
+ +{% highlight bash %} +# cat /etc/systemd/system/umount-key.service +[Unit] +Description=Unmount key card +Before=local-fs.target +After=home-arcanis.mount + +[Service] +Type=oneshot +ExecStart=/usr/bin/umount /mnt/key + +[Install] +WantedBy=local-fs.target +{% endhighlight %} + +Enable:
+ +{% highlight bash %} +systemctl enable umount-key.service +{% endhighlight %} + +Reboot. Remove backups if all is ok. If not then you did a mistake, resurrect system from emergency mode.
+ +In my case I could not to make flash mounting before home decryption. Thus I saw emergency mode on load in which I should just continue loading. There are two solutions in the Internet:
+ +rc.local.rc.local.In my opinion both of them are workarounds too much.
+ +Other solution is to mount using pam entry. In my case I have authentication without password on fingerprint so it doesn't work for me.
\ No newline at end of file diff --git a/blog/index.html b/blog/index.html index 0345898..d9f6bd9 100644 --- a/blog/index.html +++ b/blog/index.html @@ -23,6 +23,6 @@ hastr: true {{ post.title }}{{ post.date | date_to_string }}
-{{ post.description }} +{{ post.description }}
Tags: {{ post.tags }}
{% endfor %} diff --git a/resources/papers/single-door.jpg b/resources/papers/single-door.jpg new file mode 100644 index 0000000..850e953 Binary files /dev/null and b/resources/papers/single-door.jpg differ diff --git a/ru/_posts/2014-12-12-encryption-home-directory.html b/ru/_posts/2014-12-12-encryption-home-directory.html new file mode 100644 index 0000000..0afda3f --- /dev/null +++ b/ru/_posts/2014-12-12-encryption-home-directory.html @@ -0,0 +1,172 @@ +--- +category: ru +type: paper +hastr: true +layout: paper +tags: linux, systemd, ecryptfs +title: Как зашифровать хомяк и не об%$#аться. For dummies +short: ecnryption-home-directory +description:
s/$USER/имя пользователя/):
+
+{% highlight bash %}
+mv /home/{$USER,$USER-org}
+mkdir /home/$USER
+chmod 700 /home/$USER
+chown $USER:users /home/$USER
+{% endhighlight %}
+
+ Самое распространенное решение в интернетах - воспользоваться автоматическими тулзами. Однако в нашем случае они не подходят, так как нам необходимо импортировать сигнатуру ключа / пароля, что при данном решении невозможно (или у автора руки кривые).
+ +Делается шифрование следующим образом (lol):
+ +{% highlight bash %} +mount -t ecryptfs /home/$USER /home/$USER +{% endhighlight %} + +В процессе он у нас задаст несколько вопросов (я предлагаю первое монтирование делать в интерактивном режиме). Ответы можно взять примерно такие (в комментариях показано, что эти опции делают), обратите внимание, что если вы что то измените, то изменится и некоторые строчки далее:
+ +{% highlight bash %} +# ключ или сертификат. Второе надежнее, но до тех пор пока не потеряете %) +Select key type to use for newly created files: + 1) passphrase + 2) openssl +Selection: 1 +# пароль +Passphrase: +# шифрование, ставим берем дефолт +Select cipher: + 1) aes: blocksize = 16; min keysize = 16; max keysize = 32 + 2) blowfish: blocksize = 8; min keysize = 16; max keysize = 56 + 3) des3_ede: blocksize = 8; min keysize = 24; max keysize = 24 + 4) twofish: blocksize = 16; min keysize = 16; max keysize = 32 + 5) cast6: blocksize = 16; min keysize = 16; max keysize = 32 + 6) cast5: blocksize = 8; min keysize = 5; max keysize = 16 +Selection [aes]: 1 +# размер ключа, берем дефолт +Select key bytes: + 1) 16 + 2) 32 + 3) 24 +Selection [16]: 1 +# разрешать читать/писать в нешифрованные файлы в точке монтирования +Enable plaintext passthrough (y/n) [n]: n +# включить шифрование имен файлов +Enable filename encryption (y/n) [n]: y +Filename Encryption Key (FNEK) Signature [360d0573e701851e]: +# многабукафниасилил +Attempting to mount with the following options: + ecryptfs_unlink_sigs + ecryptfs_fnek_sig=360d0573e701851e + ecryptfs_key_bytes=16 + ecryptfs_cipher=aes + ecryptfs_sig=360d0573e701851e +WARNING: Based on the contents of [/root/.ecryptfs/sig-cache.txt], +it looks like you have never mounted with this key +before. This could mean that you have typed your +passphrase wrong. + +# подтверждаем, выходим +Would you like to proceed with the mount (yes/no)? : yes +Would you like to append sig [360d0573e701851e] to +[/root/.ecryptfs/sig-cache.txt] +in order to avoid this warning in the future (yes/no)? : yes +Successfully appended new sig to user sig cache file +Mounted eCryptfs +{% endhighlight %} + +Далее просто копируем файлы из родного хомяка:
+ +{% highlight bash %} +cp -a /home/$USER-org/. /home/$USER +{% endhighlight %} + +Создадим файл на флешке (я использовал microSD) со следующим содержанием (пароль только поставьте свой):
+ +{% highlight bash %} +passphrase_passwd=someverystronguniqpassword +{% endhighlight %} + +Добавим автомонтирование флешки (направление /mnt/key) в fstab с опцией ro, например так:
Теперь настроим монтирование хомяка. Опции монтирования можно подглядеть как то так:
+ +{% highlight bash %} +mount | grep ecryptfs +{% endhighlight %} + +Однако замечу, что там указаны не все опции, необходимо добавить также key, no_sig_cache, ecryptfs_passthrough. Таким образом, для systemd mount-юнит выглядит примерно так (любители shell-простыней смогут написать свой демон, потому что через fstab не сработает просто так (см. ниже)).
XXXXX нужно заменить на сигнатуру из опций, с которыми сейчас смонтирована директория. Также нужно вставить имя пользователя и отредактировать путь к файлу с паролем (и имя mount-юнита), если это необходимо. Автозагрука:
Сервис для отмонтирования флешки, когда она не нужна будет:
+ +{% highlight bash %} +# cat /etc/systemd/system/umount-key.service +[Unit] +Description=Unmount key card +Before=local-fs.target +After=home-arcanis.mount + +[Service] +Type=oneshot +ExecStart=/usr/bin/umount /mnt/key + +[Install] +WantedBy=local-fs.target +{% endhighlight %} + +Включаем:
+ +{% highlight bash %} +systemctl enable umount-key.service +{% endhighlight %} + +Перезагружаемся, если все ок, удаляем бекап. Если нет - значит что то где то неправильно сделали, восстанавливаем из режима восстановления.
+ +В моем случае, мне не получилось заставить флешку монтироваться раньше. Таким образом на загрузке я попадал в консоль восстановления из которой нужно было просто продолжить загрузку. Существующие в интернете методы предлагают два возможных варианта:
+ +rc.local.rc.local.Оба варианта меня не устроили в виду их костыльности.
+ +Другое распространенное предложение - монтировать через запись в настройках pam. Мне этот вариант не подходит, так как у меня авторизация беспарольная по отпечатку пальца.
\ No newline at end of file diff --git a/ru/blog/index.html b/ru/blog/index.html index d66d2d3..301ddb0 100644 --- a/ru/blog/index.html +++ b/ru/blog/index.html @@ -24,6 +24,6 @@ hastr: true {{ post.title }}{% include shortdate_to_ru.html %}
-{{ post.description }} +{{ post.description }}
Тэги: {{ post.tags }}
{% endfor %}