「Dm-crypt/root 以外のファイルシステムの暗号化」の版間の差分

提供: ArchWiki
ナビゲーションに移動 検索に移動
 
(戻るリンクを削除)
(同じ利用者による、間の4版が非表示)
1行目: 1行目:
 
{{Lowercase title}}
 
{{Lowercase title}}
[[Category:セキュリティ]]
+
[[Category:暗号化]]
 
[[Category:ファイルシステム]]
 
[[Category:ファイルシステム]]
 
[[en:dm-crypt/Encrypting a non-root file system]]
 
[[en:dm-crypt/Encrypting a non-root file system]]
[[dm-crypt]] に戻る。
 
 
 
以下は dm-crypt で root 以外のファイルシステムを暗号化するサンプルです。
 
以下は dm-crypt で root 以外のファイルシステムを暗号化するサンプルです。
  +
 
== 概要 ==
 
== 概要 ==
   
13行目: 12行目:
   
 
== パーティション ==
 
== パーティション ==
  +
この例では {{ic|/home}} パーティションの暗号化を説明しますが、root 以外の同じようなパーティションなら同じ方法で暗号化できます。
This example covers the encryption of the {{ic|/home}} partition, but it can be applied to any other comparable non-root partition containing user data.
 
   
  +
{{Tip|特定のユーザーの {{ic|/home}} ディレクトリをパーティション上に配置することも、全てのユーザーの {{ic|/home}} ディレクトリで共通のパーティションを作成することもできます。}}
{{Tip|You can either have a single user's {{ic|/home}} directory on a partition, or create a common partition for all user's {{ic|/home}} partitions.}}
 
   
  +
まず、パーティションを完全に消去することでパーティションの準備をしてください。[[Dm-crypt/ドライブの準備#ハードディスクドライブの完全消去]] を参照。
First, prepare the partition by securely erasing it, see [[Dm-crypt/Drive preparation#Secure erasure of the hard disk drive]].
 
   
  +
そして次のコマンドで LUKS ヘッダーを設定:
Then setup the LUKS header with:
 
 
# cryptsetup ''options'' luksFormat ''device''
 
# cryptsetup ''options'' luksFormat ''device''
   
  +
{{ic|''device''}} は先に作成したパーティションに置き換えて下さい。{{ic|''options''}} に利用できるオプションなどは [[Dm-crypt/デバイスの暗号化#LUKS モードの暗号化オプション]] を見て下さい。
Replace {{ic|''device''}} with the previously created partition. See [[Dm-crypt/Device encryption#Encryption options for LUKS mode]] for details like the available {{ic|''options''}}.
 
   
  +
暗号化されたパーティションにアクセスできるようにするには、デバイスマッパーでロックを解除します:
To gain access to the encrypted partition, unlock it with the device mapper, using:
 
 
# cryptsetup open ''device'' ''name''
 
# cryptsetup open ''device'' ''name''
   
  +
パーティションを解錠した後は {{ic|/dev/mapper/''name''}} から利用できるようになります。お好きな[[ファイルシステム]]を作成してください:
After unlocking the partition, it will be available at {{ic|/dev/mapper/''name''}}. Now create a [[file system]] of your choice with:
 
 
# mkfs.''fstype'' /dev/mapper/''name''
 
# mkfs.''fstype'' /dev/mapper/''name''
   
  +
ファイルシステムを {{ic|/home}} にマウントするか、誰か一人のユーザーにだけアクセス可能にしたい場合は {{ic|/home/''username''}} にマウントします。[[#手動でマウント・アンマウント]] を見て下さい。
Mount the file system to {{ic|/home}}, or if it should be accessible to only one user to {{ic|/home/''username''}}, see [[#Manual mounting and unmounting]].
 
   
  +
{{Tip|一度アンマウントしてからマウントしてみて、正しくマッピングされているか確認してください。}}
{{Tip|Unmount and mount once to verify that the mapping is working as intended.}}
 
   
 
=== 手動でマウント・アンマウント ===
 
=== 手動でマウント・アンマウント ===
  +
パーティションをマウントするには:
To mount the partition:
 
   
 
# cryptsetup --type luks open ''device'' ''name''
 
# cryptsetup --type luks open ''device'' ''name''
 
# mount -t ext4 /dev/mapper/''name'' /mnt/home
 
# mount -t ext4 /dev/mapper/''name'' /mnt/home
   
  +
パーティションをアンマウントするには:
To unmount it:
 
   
 
# umount /mnt/home
 
# umount /mnt/home
 
# cryptsetup close ''name''
 
# cryptsetup close ''name''
  +
  +
{{Tip|[[GVFS]] でも暗号化パーティションをマウントできます。GVFS に対応しているファイルマネージャ (例: [[Thunar]]) を使ってパーティションをマウントすると、パスワードダイアログが表示されます。他のデスクトップを使用している場合、{{Aur|zulucrypt}} で GUI が利用できます。}}
   
 
=== ロック解除とマウントの自動化 ===
 
=== ロック解除とマウントの自動化 ===
   
  +
パーティションのロックの解除とファイルシステムのマウントを自動化する方法は複数あります。
There are two different solutions for automating the process of unlocking the partition and mounting its filesystem.
 
   
==== Crypttab ====
+
==== 起動時 ====
   
  +
{{ic|/etc/crypttab}} 設定ファイルを使用することで、起動時に systemd によって自動的にファイルが読み取られロックが解除されます。全てのユーザーの home パーティションに共通のパーティションを使用する場合や、他の暗号化ブロックデバイスを自動的にマウントしたい場合に推奨される方法です。
Using the {{ic|/etc/crypttab}} configuration file, unlocking happens at boot time by systemd's automatic parsing. This is the recommended solution if you want to use one common partition for all user's home partitions or automatically mount another encrypted block device.
 
   
See [[Dm-crypt/System configuration#crypttab]] for references and [[Dm-crypt/System configuration#Mounting at boot time]] for an example set up.
+
詳しくは [[Dm-crypt/システム設定#crypttab]] を見て下さい。設定例は [[Dm-crypt/システム設定#起動時にマウント]] を見て下さい。
   
==== Pam mount ====
+
==== ユーザーのログイン時 ====
With Pam mount, unlocking happens on user login: this is the recommended solution if you want to have a single user's home directory on a partition.
 
   
  +
''pam_exec'' を使って、ユーザーのログイン時にパーティションを解錠できます (''cryptsetup open''): 特定のユーザーのホームディレクトリだけがパーティションにある場合に推奨される方法です。[[dm-crypt/ログイン時にマウント]]を見てください。
See [[Pam mount]].
 
  +
  +
[[pam_mount]] を使ってユーザーのログイン時に解錠することもできます。
   
 
== Loop デバイス ==
 
== Loop デバイス ==
   
  +
ループデバイスを使って util-linux の標準ツール {{ic|losetup}} でファイルにブロックデバイスをマップすることができます。ファイルにはファイルシステムが含まれ、他のファイルシステムと同じように使うことが可能です。暗号化されたコンテナを作成するツールとしては [[TrueCrypt]] が有名ですが、ループデバイスファイルシステムを使って LUKS で暗号化することで同じような機能が実現できると考えてください。
A loop device enables to map a blockdevice to a file with the standard util-linux tool {{ic|losetup}}. The file can then contain a filesystem, which can be used quite like any other filesystem. A lot of users know [[Truecrypt]] as a tool to create encrypted containers. Just about the same functionality can be achieved with a loopback filesystem encrypted with LUKS and is shown in the following example.
 
   
  +
まず、適切な[[乱数生成|乱数生成器]]を使用して、暗号化するコンテナを作成します:
First, start by creating an encrypted container, using an appropriate [[Random number generation|random number generator]]:
 
   
 
# dd if=/dev/urandom of=/bigsecret bs=1M count=10
 
# dd if=/dev/urandom of=/bigsecret bs=1M count=10
   
  +
このコマンドで10メガバイトの容量の {{ic|bigsecret}} ファイルが作成されます。
This will create the file {{ic|bigsecret}} with a size of 10 megabytes.
 
   
  +
{{Note|後でコンテナの大きさを[[Dm-crypt/デバイスの暗号化#ループバックファイルシステム|変更]]しなくてもよいように、暗号化するファイルの合計容量も大きいサイズを割り当ててください。内部ファイルシステムによって関連付けられるメタデータも保存する必要があるためです。LUKS モードを使用する場合、メタデータヘッダーは1〜2メガバイトも必要になります。}}
{{Note|To avoid having to [[#Resizing the loopback filesystem|resize]] the container later on, make sure to make it larger than the total size of the files to be encrypted, in order to at least also host the associated metadata needed by the internal file system. If you are going to use LUKS mode, its metadata header requires one to two megabytes alone.}}
 
   
  +
次にデバイスノード {{ic|/dev/loop0}} を作成して、コンテナをマウント・利用できるようにします:
Next create the device node {{ic|/dev/loop0}}, so that we can mount/use our container:
 
   
 
# losetup /dev/loop0 /bigsecret
 
# losetup /dev/loop0 /bigsecret
   
{{Note|If it gives you the error {{ic|/dev/loop0: No such file or directory}}, you need to first load the kernel module with {{ic|modprobe loop}}. These days (Kernel 3.2) loop devices are created on demand. Ask for a new loop device with {{ic|# losetup -f}}.}}
+
{{Note|{{ic|/dev/loop0: No such file or directory}} というエラーが吐かれる場合、先に {{ic|modprobe loop}} でカーネルモジュールをロードしてください。最近は (カーネル 3.2) ループデバイスは必要に応じて作成されるようになっています。新しいループデバイスの作成は {{ic|# losetup -f}} で出来ます。}}
   
  +
ここからの作業は [[#パーティション]] と同じです。違うのはコンテナは既にランダム化されており消去する必要がないということだけです。
From now on the procedure is the same as for [[#Partition]], except for the fact that the container is already randomised and will not need another secure erasure.
 
   
  +
{{Tip|''dm-crypt'' のコンテナは高い柔軟性を持っています。[[Tomb]] の特徴とドキュメントを見てください。Tomb は高速かつ柔軟な管理ができる ''dm-crypt'' スクリプトラッパーです。}}
{{Tip|Containers with ''dm-crypt'' can be very flexible. Have a look at the features and documentation of [[Tomb]]. It provides a ''dm-crypt'' script wrapper for fast and flexible handling.}}
 
   
 
=== 手動でマウント・アンマウント ===
 
=== 手動でマウント・アンマウント ===
  +
コンテナをアンマウントするには:
To unmount the container:
 
   
 
# umount /mnt/secret
 
# umount /mnt/secret
89行目: 91行目:
 
# losetup -d /dev/loop0
 
# losetup -d /dev/loop0
   
  +
コンテナをマウントするには:
To mount the container again:
 
   
 
# losetup /dev/loop0 /bigsecret
 
# losetup /dev/loop0 /bigsecret
 
# cryptsetup --type luks open /dev/loop0 secret
 
# cryptsetup --type luks open /dev/loop0 secret
 
# mount -t ext4 /dev/mapper/secret /mnt/secret
 
# mount -t ext4 /dev/mapper/secret /mnt/secret
 
=== loopback ファイルシステムのサイズの変更 ===
 
First unmount the encrypted container:
 
# umount /mnt/secret
 
# cryptsetup close secret
 
# losetup -d /dev/loop0
 
 
Next, expand the container file with the size of the data you want to add:
 
 
# dd if=/dev/urandom bs=1M count=1024 | cat - >> /bigsecret
 
 
{{Warning|Be careful to really use '''two''' {{ic|>}}, or you will override your current container.}}
 
 
Now map the container to the loop device:
 
# losetup /dev/loop0 /bigsecret
 
# cryptsetup --type luks open /dev/loop0 secret
 
 
After this, resize the encrypted part of the container to the maximum size of the container file:
 
# cryptsetup resize secret
 
 
Finally, perform a filesystem check and, if it is ok, resize it (example for ext2/3/4):
 
# e2fsck -f /dev/mapper/secret
 
# resize2fs /dev/mapper/secret
 
 
You can now mount the container again:
 
# mount /dev/mapper/secret /mnt/secret
 

2017年12月24日 (日) 00:22時点における版

以下は dm-crypt で root 以外のファイルシステムを暗号化するサンプルです。

概要

セカンダリファイルシステムの暗号化は基本的に重要なデータだけを保護します。オペレーティングシステムやプログラムファイルは暗号化されないままです。USB ドライブなどの外部メディアを暗号化したいときは、別のコンピュータに安全に持っていけるようになるので便利です。また、アクセスする人ごとに暗号化するデータを選択することもできます。

dm-crypt はブロックレベルの暗号化レイヤーなので、完全なデバイスやパーティションloop デバイスなどしか暗号化できません。個別のファイルを暗号化するには、eCryptfsEncFS などのファイルシステムレベルの暗号化レイヤーが必要です。個人データを守る方法に関する一般的な情報はディスク暗号化を見て下さい。

パーティション

この例では /home パーティションの暗号化を説明しますが、root 以外の同じようなパーティションなら同じ方法で暗号化できます。

ヒント: 特定のユーザーの /home ディレクトリをパーティション上に配置することも、全てのユーザーの /home ディレクトリで共通のパーティションを作成することもできます。

まず、パーティションを完全に消去することでパーティションの準備をしてください。Dm-crypt/ドライブの準備#ハードディスクドライブの完全消去 を参照。

そして次のコマンドで LUKS ヘッダーを設定:

# cryptsetup options luksFormat device

device は先に作成したパーティションに置き換えて下さい。options に利用できるオプションなどは Dm-crypt/デバイスの暗号化#LUKS モードの暗号化オプション を見て下さい。

暗号化されたパーティションにアクセスできるようにするには、デバイスマッパーでロックを解除します:

# cryptsetup open device name

パーティションを解錠した後は /dev/mapper/name から利用できるようになります。お好きなファイルシステムを作成してください:

# mkfs.fstype /dev/mapper/name

ファイルシステムを /home にマウントするか、誰か一人のユーザーにだけアクセス可能にしたい場合は /home/username にマウントします。#手動でマウント・アンマウント を見て下さい。

ヒント: 一度アンマウントしてからマウントしてみて、正しくマッピングされているか確認してください。

手動でマウント・アンマウント

パーティションをマウントするには:

# cryptsetup --type luks open device name
# mount -t ext4 /dev/mapper/name /mnt/home

パーティションをアンマウントするには:

# umount /mnt/home
# cryptsetup close name
ヒント: GVFS でも暗号化パーティションをマウントできます。GVFS に対応しているファイルマネージャ (例: Thunar) を使ってパーティションをマウントすると、パスワードダイアログが表示されます。他のデスクトップを使用している場合、zulucryptAUR で GUI が利用できます。

ロック解除とマウントの自動化

パーティションのロックの解除とファイルシステムのマウントを自動化する方法は複数あります。

起動時

/etc/crypttab 設定ファイルを使用することで、起動時に systemd によって自動的にファイルが読み取られロックが解除されます。全てのユーザーの home パーティションに共通のパーティションを使用する場合や、他の暗号化ブロックデバイスを自動的にマウントしたい場合に推奨される方法です。

詳しくは Dm-crypt/システム設定#crypttab を見て下さい。設定例は Dm-crypt/システム設定#起動時にマウント を見て下さい。

ユーザーのログイン時

pam_exec を使って、ユーザーのログイン時にパーティションを解錠できます (cryptsetup open): 特定のユーザーのホームディレクトリだけがパーティションにある場合に推奨される方法です。dm-crypt/ログイン時にマウントを見てください。

pam_mount を使ってユーザーのログイン時に解錠することもできます。

Loop デバイス

ループデバイスを使って util-linux の標準ツール losetup でファイルにブロックデバイスをマップすることができます。ファイルにはファイルシステムが含まれ、他のファイルシステムと同じように使うことが可能です。暗号化されたコンテナを作成するツールとしては TrueCrypt が有名ですが、ループデバイスファイルシステムを使って LUKS で暗号化することで同じような機能が実現できると考えてください。

まず、適切な乱数生成器を使用して、暗号化するコンテナを作成します:

# dd if=/dev/urandom of=/bigsecret bs=1M count=10

このコマンドで10メガバイトの容量の bigsecret ファイルが作成されます。

ノート: 後でコンテナの大きさを変更しなくてもよいように、暗号化するファイルの合計容量も大きいサイズを割り当ててください。内部ファイルシステムによって関連付けられるメタデータも保存する必要があるためです。LUKS モードを使用する場合、メタデータヘッダーは1〜2メガバイトも必要になります。

次にデバイスノード /dev/loop0 を作成して、コンテナをマウント・利用できるようにします:

# losetup /dev/loop0 /bigsecret
ノート: /dev/loop0: No such file or directory というエラーが吐かれる場合、先に modprobe loop でカーネルモジュールをロードしてください。最近は (カーネル 3.2) ループデバイスは必要に応じて作成されるようになっています。新しいループデバイスの作成は # losetup -f で出来ます。

ここからの作業は #パーティション と同じです。違うのはコンテナは既にランダム化されており消去する必要がないということだけです。

ヒント: dm-crypt のコンテナは高い柔軟性を持っています。Tomb の特徴とドキュメントを見てください。Tomb は高速かつ柔軟な管理ができる dm-crypt スクリプトラッパーです。

手動でマウント・アンマウント

コンテナをアンマウントするには:

# umount /mnt/secret
# cryptsetup close secret
# losetup -d /dev/loop0

コンテナをマウントするには:

# losetup /dev/loop0 /bigsecret
# cryptsetup --type luks open /dev/loop0 secret
# mount -t ext4 /dev/mapper/secret /mnt/secret