「ECryptfs」の版間の差分
(en:ECryptfsへの転送ページ) |
|||
1行目: | 1行目: | ||
+ | {{Lowercase title}} |
||
− | #redirect[[en:ECryptfs]] |
||
+ | [[Category:セキュリティ]] |
||
+ | [[Category:ファイルシステム]] |
||
+ | [[en:ECryptfs]] |
||
+ | [[fr:Encryption avec eCryptfs]] |
||
+ | [[it:System Encryption with eCryptfs]] |
||
+ | [[ru:ECryptfs]] |
||
+ | {{Related articles start}} |
||
+ | {{Related|ディスク暗号化}} |
||
+ | {{Related articles end}} |
||
+ | この記事では [https://launchpad.net/ecryptfs eCryptfs] の基本的な使い方を説明します。プライベートな暗号化ディレクトリを {{ic|$HOME}} ディレクトリに作成して機密ファイルや個人情報を保存する方法を解説していきます。 |
||
+ | |||
+ | ''ブロックデバイスの暗号化レイヤー''を提供する [[dm-crypt]] とは異なり eCryptfs はファイルシステムそのものです – [http://en.wikipedia.org/wiki/Cryptographic_filesystems スタック暗号化ファイルシステム] になります。その違いについては [http://ksouedu.com/doc/ecryptfs-utils/ecryptfs-faq.html#compare この表] や[[ディスク暗号化#比較表]]を参照してください。大きな特徴として既存のファイルシステム上に暗号化が積み重ねられるという点が挙げられます。eCryptfs はあらゆる既存のディレクトリにマウントすることができ、特別なパーティション (や領域の事前割り当て) を必要としません。 |
||
+ | |||
+ | {{Note|この記事は再構築中です。あるべき場所に情報がない場合は、再構築する前の版 [https://wiki.archlinux.org/index.php?title=ECryptfs&oldid=291214] を見て下さい。}} |
||
+ | |||
+ | == 基本 == |
||
+ | |||
+ | 先に述べたように eCryptfs には特殊なパーティションや予約済みの領域をディスク上に配置する必要がありません。代わりに、eCryptfs を既存のディレクトリ上にマウントしてディレクトリを保護することができます。例えば、ユーザーの {{ic|$HOME}} ディレクトリを全体的に保護したり、逆に特定のディレクトリだけを保護したりできます。暗号のメタデータは全てファイルのヘッダの中に保存されます。つまり、暗号化したデータは簡単に移動したり、バックアップ・復元できるということです。他にも利点はありますが、欠点も存在します。例として eCryptfs はパーティション全体を暗号化するのには適していません。また、スワップ領域を eCryptfs で保護することは不可能です (もちろん、[[Dm-crypt/スワップの暗号化]]と組み合わせることはできますが)。ディスク暗号化を初めて設定する場合、スワップの暗号化などのポイントは[[ディスク暗号化#準備]]に書かれています。 |
||
+ | |||
+ | eCryptfs を使うなら以下がポイントです: |
||
+ | * スタックファイルシステムとして、eCryptfs ディレクトリのマウントは (スタックされた) 暗号化ディレクトリを他の暗号化されていないマウントポイント (ディレクトリ) マウントすることを意味します。 |
||
+ | * ユーザー間で暗号化ディレクトリを共有することができます。ただし、暗号化のパスワードは一つだけなのでパスワードも共有する必要があります。(別々のパスフレーズを使って) 別々に暗号化されたファイルを一つのディレクトリで共有することもできます。 |
||
+ | * ドキュメントの中では eCryptfs の専門用語が頻繁に登場します: |
||
+ | ** eCryptfs のドキュメントやこの記事では暗号化されるディレクトリは '''lower''' (下層) と呼称して暗号化されていないディレクトリは '''upper''' (上層) ディレクトリと呼びます。この記事とは無関係ですが、Linux 3.18 で導入された "overlay" ファイルシステム ([https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/Documentation/filesystems/overlayfs.txt]) では同じ upper/lower という単語をファイルシステムのスタック化について使います。 |
||
+ | ** '''mount''' パスフレーズ (キー) は暗号化されたファイルへのアクセス権限を与えます。つまり暗号化を解除します。eCryptfs は '''wrapped''' という言葉を使って mount パスフレーズが暗号的に安全であることを示します。 |
||
+ | ** {{ic|FEFEK}} は '''F'''ile's '''E'''ncryption key '''E'''ncryption '''Key''' のことです ([https://www.kernel.org/doc/Documentation/security/keys-ecryptfs.txt カーネルドキュメント] を参照)。 |
||
+ | ** {{ic|FNEK}} は '''F'''ile '''N'''ame '''E'''ncryption '''K'''ey のことです。暗号化ディレクトリに保存されたファイル名を暗号化する鍵になります (任意)。 |
||
+ | |||
+ | eCryptfs を使う前に、以下の欠点が障害にならないか確認してください。 |
||
+ | |||
+ | === 欠陥 === |
||
+ | |||
+ | * 変数がハードコードされている |
||
+ | :eCryptfs の使いやすさは主として {{Pkg|ecryptfs-utils}} パッケージの "Ubuntu tools" に依存しています。決定的な欠点として、ツールの中では多数の変数 (暗号化オプションやディレクトリパス) が決め打ちされています。変数を変更するとなると大変面倒な手動設定が必要ということです。 |
||
+ | * ネットワークストレージマウント |
||
+ | :eCryptfs にはネットワークストレージに関する長年の [https://bugs.launchpad.net/ecryptfs/+bug/277578 バグ] や機能リクエストが存在します。暗号化したディレクトリの中身をネットワークのバックアップストレージに複製することは可能です。しかしながら、ネットワークストレージ上に直接、暗号化ディレクトリを保存してそれをローカルでマウントしたい場合、まずネットワークツール (NFS や Samba など) に対応した解決方法を検索する必要があります。よく分からない場合、[[EncFS]] を使うのがベターです。 |
||
+ | |||
+ | * スパースファイル |
||
+ | :eCryptfs は[[スパースファイル]]を扱うことができません。バグと言われることもありますが、[[ディスク暗号化#スタックファイルシステムの暗号化|スタックファイルシステムの暗号化]]として当然そうなるべきことです。例えば、eCryptfs ディレクトリに {{ic|truncate -s 1G file.img}} で 1GB の暗号化データを作成してファイルシステムに保存する場合、それに対応するリソース (ディスク容量, データのスループット) が必要になります。暗号化しなければ、同じファイルをスパースファイルとして効率的にファイルシステムに保存できます。[[ディスク暗号化#ブロックデバイスの暗号化|ブロックデバイスの暗号化]]はファイルシステムの出力だけを暗号化します。 |
||
+ | |||
+ | :巨大なディレクトリ構造を暗号化するときは予めこのことを考えておく必要があります。大抵の場合、スパースファイルを使えないことが致命的な問題になることはありません。(eCryptfs の標準の {{ic|.Private}} ディレクトリではなく) 暗号化を施さない {{ic|.Public}} ディレクトリにスパースファイルを保存する方法と、{{ic|.Public}} で ''dm-crypt' の[[dm-crypt/root 以外のファイルシステムの暗号化#Loop デバイス|コンテナ]]を使う方法があります。 |
||
+ | |||
+ | == セットアップ例の概要 == |
||
+ | |||
+ | The following [[#Setup & mounting]] section describes alternatives using eCryptfs to encrypt a data directory. The alternatives start with [[#Using the Ubuntu tools]], which make eCryptfs usage particularly easy and also safe against user errors. This also applies to [[#Encrypting a home directory]] with the tools. During setup, instructions are given on the console by the scripts. The [[#Using ecryptfs-simple]] section then introduces an alternative package to aide using eCryptfs. The [[#Manual setup]] section then describes the setup using the {{ic|ecryptfs}} filesystem directly. The first subsection ([[#With ecryptfs-utils]]) still uses one more script and is suggested to read to familiarize with the setup of the manual options before using them [[#Without ecryptfs-utils]]. |
||
+ | |||
+ | The alternatives include |
||
+ | # the setup step for the encrypted directory structures |
||
+ | # the setup to mount, unmount the directory at runtime manually and/or automatically at user login |
||
+ | Each of the described alternative examples can be removed after setup very easily, so do not refrain from testing which suits your needs best. |
||
+ | |||
+ | == セットアップ & マウント == |
||
+ | |||
+ | eCryptfs はバージョン 2.6.19 から Linux に含まれています。ただし eCryptfs を使うにはユーザースペースツールが必要になります。[[公式リポジトリ]]の {{pkg|ecryptfs-utils}} パッケージに入っています。 |
||
+ | |||
+ | パッケージをインストールしたら {{ic|ecryptfs}} モジュールをロードしてからセットアップに進みます: |
||
+ | # modprobe ecryptfs |
||
+ | |||
+ | セットアップを始める前に、eCryptfs のドキュメントを確認してください。素晴らしい [http://ecryptfs.org/documentation.html マニュアルページ] が付属しています。 |
||
+ | |||
+ | {{Tip|{{Pkg|linux-grsec}} を使用している場合、{{ic|ecryptfs-mount-private}} ラッパーを実行しても暗号モジュールは自動ロードされないことがあります (2014年11月)。その場合、手動でモジュールをロードしてください。例えば root で {{ic|modprobe md5}} を実行して次の起動時にロードされるように[[カーネルモジュール#ロード|設定]]してください。}} |
||
+ | |||
+ | === Ubuntu のツールを使う === |
||
+ | |||
+ | Most of the user-friendly convenience tools installed by the ''ecryptfs-utils'' package assume a very specific eCryptfs setup, namely the one that is officially used by Ubuntu (where it can be selected as an option during distro installation). Unfortunately, these choices are not just default options but are actually hard-coded in the tools. If this set-up does not suit your needs, then you can not use the convenience tools and will have to follow the steps at [[#Manual setup]] instead. |
||
+ | |||
+ | The set-up used by these tools is as follows: |
||
+ | |||
+ | * each user can have '''only one encrypted directory''' that is managed by these tools: |
||
+ | ** either full {{ic|$HOME}} directory encryption, or |
||
+ | ** a single encrypted data directory (by default {{ic|~/Private/}}, but this can be customized). |
||
+ | * the '''lower directory''' for each user is always {{ic|~/.Private/}}<br><small>(in the case of full home dir encryption, this will be a symlink to the actual location at {{ic|/home/.ecryptfs/$USER/.Private/}})</small> |
||
+ | * the '''encryption options''' used are: |
||
+ | ** ''cipher:'' AES |
||
+ | ** ''key length:'' 16 bytes (128 bits) |
||
+ | ** ''key management scheme:'' passphrase |
||
+ | ** ''plaintext passthrough:'' enabled |
||
+ | * the '''configuration / control info''' for the encrypted directory is stored in a bunch of files at {{ic|~/.ecryptfs/}}:<br><small>(in the case of full home dir encryption, this will be a symlink to the actual location at {{ic|/home/.ecryptfs/$USER/.ecryptfs/}})</small> |
||
+ | ** {{ic|Private.mnt}} ''[plain text file]'' - contains the path where the upper directory should be mounted (e.g. {{ic|/home/lucy}} or {{ic|/home/lucy/Private}}) |
||
+ | ** {{ic|Private.sig}} ''[plain text file]'' - contains the signature used to identify the mount passphrase in the kernel keyring |
||
+ | ** {{ic|wrapped-passphrase}} ''[binary file]'' - the mount passphrase, encrypted with the login passphrase |
||
+ | ** {{ic|auto-mount}}, {{ic|auto-umount}} ''[empty files]'' - if they exist, the {{ic|pam_ecryptfs.so}} module will (assuming it is loaded) automatically mount/unmount this encrypted directory when the user logs in/out |
||
+ | |||
+ | ==== データディレクトリの暗号化 ==== |
||
+ | For a full {{ic|$HOME}} directory encryption see [[#Encrypting a home directory]] |
||
+ | |||
+ | Before the data directory encryption is setup, decide whether it should later be mounted manually or automatically with the user log-in. |
||
+ | |||
+ | To encrypt a single data directory as a user and mount it manually later, run: |
||
+ | $ ecryptfs-setup-private --nopwcheck --noautomount |
||
+ | |||
+ | and follow the instructions. The option {{ic|--nopwcheck}} enables you to choose a passphrase different to the user login passphrase and the option {{ic|--noautomount}} is self-explanatory. So, if you want to setup the encrypted directory automatically on log-in later, just ''leave out'' both options right away. |
||
+ | |||
+ | The script will automatically create the {{ic|~/.Private/}} and {{ic|~/.ecryptfs/}} directory structures as described in the box above. It will also ask for two passphrases: |
||
+ | |||
+ | ;'''login passphrase''': This is the password you will have to enter each time you want to mount the encrypted directory. If you want auto-mounting on login to work, it has to be the same password you use to login to your user account. |
||
+ | |||
+ | ;'''mount passphrase''': This is used to derive the actual file encryption master key. Thus, you should not enter a custom one unless you know what you are doing - instead press Enter to let it auto-generate a secure random one. It will be encrypted using the login passphrase and stored in this encrypted form in {{ic|~/.ecryptfs/wrapped-passphrase}}. Later it will automatically be decrypted ("unwrapped") again in RAM when needed, so you never have to enter it manually. Make sure this file does not get lost, otherwise you can never access your encrypted folder again! You may want to run {{ic|ecryptfs-unwrap-passphrase}} to see the mount passphrase in unencrypted form, write it down on a piece of paper, and keep it in a safe (or similar), so you can use it to recover your encrypted data in case the ''wrapped-passphrase'' file is accidentally lost/corrupted or in case you forget the login passphrase. |
||
+ | |||
+ | The mount point ("upper directory") for the encrypted folder will be at {{ic|~/Private}} by default, however you can manually change this right after the setup command has finished running, by doing: |
||
+ | |||
+ | $ mv ~/Private /path/to/new/folder |
||
+ | $ echo /path/to/new/folder > ~/.ecryptfs/Private.mnt |
||
+ | |||
+ | To actually use your encrypted folder, you will have to mount it - see [[#Mounting]] below. |
||
+ | |||
+ | ==== ホームディレクトリの暗号化 ==== |
||
+ | |||
+ | The following wrapper script will set up an encrypted {{ic|$HOME}} directory for a user and take care of migrating any existing files they have in their not yet encrypted home directory. Ensure that the user in question ''owns no processes'' and is ''logged out''. You also need to ensure that you have {{pkg|rsync}} and {{pkg|lsof}} installed. Once the prerequisites have been met, run: |
||
+ | |||
+ | # ecryptfs-migrate-home -u ''username'' |
||
+ | |||
+ | and follow the instructions. After the wrapper script is complete, follow the instructions for auto-mounting - see [[#Auto-mounting]] below. It is imperative that the user logs in ''before'' the next reboot, to complete the process. |
||
+ | |||
+ | ==== マウント ==== |
||
+ | |||
+ | ===== 手動 ===== |
||
+ | |||
+ | ラッパーを実行: |
||
+ | $ ecryptfs-mount-private |
||
+ | 後はパスフレーズを入力するだけで[[#Ubuntu のツールを使う|上述]]の''上層ディレクトリ''である {{ic|~/Private}} に暗号化ディレクトリをマウントできます。 |
||
+ | |||
+ | 同じように、以下を実行するとアンマウントされます: |
||
+ | $ ecryptfs-umount-private |
||
+ | |||
+ | {{Tip|If it is not required to access the private data permanently during a user session, maybe define an [[Bash#エイリアス|alias]] to speed the manual step up.}} |
||
+ | |||
+ | The tools include another script that can be very handy to access an encrypted {{ic|.Private}} data or home directory. Executing {{ic|ecryptfs-recover-private}} as root will search the system (or an optional specific path) for the directory, interactively query the passphrase for it and mount the directory. It can, for example, be used from a live-CD or different system to access the encrypted data in case of a recovery. Note that if booting from an Arch Linux ISO you must first install the {{pkg|ecryptfs-utils}} to it. Further, it will only be able to mount {{ic|.Private}} directories created with the Ubuntu tools. |
||
+ | |||
+ | ===== 自動マウント ===== |
||
+ | |||
+ | The default way to auto-mount an encrypted directory is via [[Pam_mount|PAM]]. See {{ic|man pam_ecryptfs}} and - for more details - 'PAM MODULE' in: |
||
+ | /usr/share/doc/ecryptfs-utils/README |
||
+ | |||
+ | For auto-mounting it is required that the passphrase to access the encrypted directory is synchronised with the user log-in. |
||
+ | |||
+ | The following steps set it up: |
||
+ | |||
+ | 1. Check if {{ic|~/.ecryptfs/auto-mount}}, {{ic|~/.ecryptfs/auto-umount}} and {{ic|~/.ecryptfs/wrapped-passphrase}} exist (these are automatically created by ''ecryptfs-setup-private''). |
||
+ | |||
+ | 2. Add ''ecryptfs'' to the pam-stack exactly as following to allow transparent unwrapping of the passphrase on login: |
||
+ | |||
+ | Open {{ic|/etc/pam.d/system-auth}} and ''after'' the line containing {{ic|auth required pam_unix.so}} add: |
||
+ | auth required pam_ecryptfs.so unwrap |
||
+ | Next, ''above'' the line containing {{ic|password required pam_unix.so}} insert: |
||
+ | password optional pam_ecryptfs.so |
||
+ | And finally, ''after'' the line {{ic|session required pam_unix.so}} add: |
||
+ | session optional pam_ecryptfs.so |
||
+ | |||
+ | 3. Re-login and check output of ''mount'' which should now contain a mountpoint, e.g.: |
||
+ | /home/$USER/.Private on /home/$USER/Private type ecryptfs (...) |
||
+ | for the user's encrypted directory. It should be perfectly readable at {{ic|~$HOME/Private/}}. |
||
+ | |||
+ | The latter should be automatically unmounted and made unavailable when the user logs off. |
||
+ | |||
+ | {{Warning|1=Unfortunately the automatic unmounting is susceptible to [https://bbs.archlinux.org/viewtopic.php?id=194509 break] with systemd and bugs are filed against it.[https://bugs.freedesktop.org/show_bug.cgi?id=72759] [https://nwrickert2.wordpress.com/2013/12/16/systemd-user-manager-ecryptfs-and-opensuse-13-1/] [https://bugs.launchpad.net/ubuntu/+source/ecryptfs-utils/+bug/313812/comments/43] [http://lists.alioth.debian.org/pipermail/pkg-systemd-maintainers/2014-October/004088.html] |
||
+ | If you experience this problem, you can test it by commenting out {{ic|-session optional pam_systemd.so}} in {{ic|/etc/pam.d/system-login}}. However, this is no solution because commenting out will break other systemd functionalities.}} |
||
+ | |||
+ | === ecryptfs-simple を使う === |
||
+ | |||
+ | [[EncFS]] と同じように任意のディレクトリをマウントすることだけに eCryptfs を使う場合 [http://xyne.archlinux.ca/projects/ecryptfs-simple/ ecryptfs-simple] を使って下さい。ecryptfs-simple は root 権限を必要とせず {{ic|/etc/fstab}} にエントリを書く必要もありません。さらに {{ic|~/.Private}} などのディレクトリにハードコードもされていません。{{AUR|ecryptfs-simple}} や [http://xyne.archlinux.ca/repos/ Xyne のリポジトリ] からパッケージを[[インストール]]できます。 |
||
+ | |||
+ | 名は体を表すとおり、使用方法はシンプルです: |
||
+ | # simple mounting |
||
+ | ecryptfs-simple /path/to/foo /path/to/bar |
||
+ | |||
+ | # automatic mounting: prompts for options on the first mount of a directory then reloads them next time |
||
+ | ecryptfs-simple -a /path/to/foo /path/to/bar |
||
+ | |||
+ | # unmounting by source directory |
||
+ | ecryptfs-simple -u /path/to/foo |
||
+ | |||
+ | # unmounting by mountpoint |
||
+ | ecryptfs-simple -u /path/to/bar |
||
+ | |||
+ | === 手動セットアップ === |
||
+ | |||
+ | The following details instructions to set up eCryptfs encrypted directories manually. The first section still relies on one extra script from the {{Pkg|ecryptfs-utils}} package. It may be an easier start and can be tried without any root rights. The [[#Without ecryptfs-utils|second]] then sets up an encrypted directory with other encryption options than the default tools. |
||
+ | |||
+ | {{Tip|The following examples use an encrypted directory ({{ic|.secret}}) different to the default, hard-coded {{ic|.Private}} in the Ubuntu tools. This is on purpose to avoid problems of erroneous [[#Auto-mounting]] when the system has PAM setup for it, as well as problems with other tools using the hard-coded defaults.}} |
||
+ | |||
+ | ==== ecryptfs-utils を使う ==== |
||
+ | |||
+ | Alternatively to using the scripts {{ic|ecryptfs-setup-private}} and {{ic|ecryptfs-mount-private}} to setup and mount eCryptfs, the same can be done directly with the binaries (which those scripts use) {{ic|ecryptfs-add-passphrase}} and {{ic|mount.ecryptfs_private}} from the {{Pkg|ecryptfs-utils}} package. Those binaries require no root privileges to work by default. |
||
+ | |||
+ | First choose an ALIAS as you like. Through this section, ALIAS will be {{ic|secret}}. Create the required directories/files: |
||
+ | $ mkdir ~/.secret ~/secret ~/.ecryptfs |
||
+ | $ touch ~/.ecryptfs/secret.conf ~/.ecryptfs/secret.sig |
||
+ | |||
+ | The {{ic|~/.secret}} directory will hold the encrypted data. The {{ic|~/secret}} directory is the mount point where {{ic|~/.secret}} will be mounted as an ecryptfs filesystem. |
||
+ | |||
+ | In the next command, replace USER with the name of the current user's home directory. Note that you should write full paths to {{ic|~/.ecryptfs/secret.conf}}. Its format looks like the one in {{ic|/etc/fstab}} without the mount options: |
||
+ | $ echo "/home/USER/.secret /home/USER/secret ecryptfs" > ~/.ecryptfs/secret.conf |
||
+ | |||
+ | A mount passphrase must be added to the keyring: |
||
+ | $ ecryptfs-add-passphrase |
||
+ | Passphrase: |
||
+ | Inserted auth tok with sig [78c6f0645fe62da0] into the user session keyring |
||
+ | |||
+ | Write the output signature ({{ic|ecryptfs_sig}}) from the previous command to {{ic|~/.ecryptfs/secret.sig}}: |
||
+ | $ echo 78c6f0645fe62da0 > ~/.ecryptfs/secret.sig |
||
+ | |||
+ | A second passphrase for filename encryption may be used. If you choose so, add it to the keyring: |
||
+ | $ ecryptfs-add-passphrase |
||
+ | Passphrase: |
||
+ | Inserted auth tok with sig [326a6d3e2a5d444a] into the user session keyring |
||
+ | |||
+ | If you run the command above, '''append''' its output signature ({{ic|ecryptfs_fnek_sig}}) to {{ic|~/.ecryptfs/secret.sig}}: |
||
+ | $ echo 326a6d3e2a5d444a >> ~/.ecryptfs/secret.sig |
||
+ | |||
+ | Finally, to mount {{ic|~/.secret}} on {{ic|~/secret}}: |
||
+ | $ mount.ecryptfs_private secret |
||
+ | |||
+ | An eCryptfs filesystem will be mounted with the following options: |
||
+ | rw,nosuid,nodev,relatime,ecryptfs_fnek_sig=326a6d3e2a5d444a,ecryptfs_sig=78c6f0645fe62da0,ecryptfs_cipher=aes,ecryptfs_key_bytes=16,ecryptfs_unlink_sigs |
||
+ | |||
+ | Except for {{ic|ecryptfs_sig}} and {{ic|ecryptfs_fnek_sig}}, the options are hard-coded. {{ic|ecryptfs_fnek_sig}} will exist only if you choose filename encryption. |
||
+ | |||
+ | To unmount {{ic|~/.secret}}: |
||
+ | $ umount.ecryptfs_private secret |
||
+ | |||
+ | ==== ecryptfs-utils を使う ==== |
||
+ | |||
+ | The ecryptfs-utils package is distributed with a few helper scripts which will help you with key management and similar tasks. If one wants, for example, make a choice about the encryption cipher, some of those scripts cannot be used. In this section we setup an encrypted data directory diverting from those defaults. |
||
+ | |||
+ | First create your private directories, in this example we will call them analogous to the previous section: {{ic|secret}} |
||
+ | $ mkdir -m 700 /home/username/{.secret,.ecryptfs} |
||
+ | $ mkdir -m 500 /home/username/secret |
||
+ | |||
+ | To summarize: |
||
+ | * Actual encrypted data will be stored in the lower {{ic|~/.secret}} directory |
||
+ | * While mounted, decrypted data will be available in {{ic|~/secret}} directory |
||
+ | ** While not mounted nothing can be written to this directory |
||
+ | ** While mounted it has the same permissions as the lower directory |
||
+ | |||
+ | Second we create the mount-passphrase ("file encryption key, encryption key", or '''fekek''') for the directory. It has to be very secure and cannot be changed easily. The ''ecryptfs-setup-private'' script offers the option to generate it from {{ic|/dev/urandom}}. In the following we do a generation similar to the [http://bazaar.launchpad.net/~ecryptfs/ecryptfs/trunk/view/head:/src/utils/ecryptfs-setup-private#L96 source] and then use ''ecryptfs-wrap-passphrase'' to wrap it with an extra password ("Arch"): |
||
+ | |||
+ | $ printf "%s\n%s" $(od -x -N 100 --width=30 /dev/random | head -n 1 | sed "s/^0000000//" | sed "s/\s*//g") "Arch" | ecryptfs-wrap-passphrase /home/username/.ecryptfs/wrapped-passphrase |
||
+ | |||
+ | The advantages of the above step are: the mount passphrase is generated from a random source and secured by extra hashing before it is stored on disk. Further, the wrap-passphrase can be changed later. |
||
+ | |||
+ | Next, we test the passphrase by loading it into the kernel keyring: |
||
+ | |||
+ | $ printf "%s" "Arch" | ecryptfs-insert-wrapped-passphrase-into-keyring /home/username/.ecryptfs/wrapped-passphrase - |
||
+ | Inserted auth tok with sig [7c5d3dd8a1b49db0] into the user session keyring |
||
+ | and manually copy the signature into the configuration: |
||
+ | $ echo "7c5d3dd8a1b49db0" > ~/.ecryptfs/secret.sig |
||
+ | |||
+ | Now we continue to setup the encryption options for the directory and prepare an user-mountable entry for {{ic|/etc/fstab}}. If you already know the eCryptfs options to use in it, you can skip the following ''mount'' and create an entry with the above signature already. |
||
+ | |||
+ | The ''mount.ecryptfs'' command needs root and does not allow for piping the passphrase unfortunately. The mount helper will ask questions about the options we want to choose ("Key type": passphrase - choose any, we only do this to generate the options to use), but let it mount: |
||
+ | |||
+ | # mount -t ecryptfs /home/username/.secret /home/username/secret |
||
+ | Passphrase: yes |
||
+ | Cipher: aes |
||
+ | Key byte: 32 |
||
+ | Plaintext passtrough: no |
||
+ | Filename encryption: no |
||
+ | Add signature to cache: yes |
||
+ | |||
+ | To summarize the parameters: |
||
+ | * The above chosen {{ic|32}} "key bytes" result in a 256 bit AES encryption (the helper scripts are hard-coded to AES with 128 bit). |
||
+ | * Plaintext passtrough enables to store and work with '''un-encrypted''' files stored in the lower directory. |
||
+ | * In eCryptfs terms the key used to protect filenames is known as "filename encryption key", or '''fnek''' |
||
+ | * '''fekek''' and '''fnek''' can be the same key or different ones at choice |
||
+ | |||
+ | To create the mount point for the user in [[fstab]], find the current mount and copy it. For example ({{ic|XY}} are placeholders here): |
||
+ | |||
+ | {{hc|# mount|2=/home/username/.secret on /home/username/secret type ecryptfs (... ecryptfs_fnek_sig=XY,ecryptfs_sig=XY,ecryptfs_cipher=aes,ecryptfs_key_bytes=32,ecryptfs_unlink_sigs, user)}} |
||
+ | |||
+ | Or, alternatively, append it into {{ic|/etc/fstab}} to edit it: |
||
+ | |||
+ | # mount | grep secret >> /etc/fstab |
||
+ | |||
+ | Before continuing, we can already un-mount the temporary mount we used to generate the options: |
||
+ | # umount /home/username/secret |
||
+ | |||
+ | Now the mount line has to be edited into the correct format, the mount options {{ic|nosuid,nodev,noexec,relatime}} before the first ''ecryptfs'' option are default and can be left out. But what we need to add is the correct signatures for the passphrases to replace the ones of the current mount: |
||
+ | # cat /home/username/.ecryptfs/secret.sig |
||
+ | 7c5d3dd8a1b49db0 |
||
+ | |||
+ | We also need to add the options {{ic|user}} and {{ic|noauto}}. After the edit, the entry will look similar to (bold entries added): |
||
+ | |||
+ | {{hc|/etc/fstab|2=/home/username/.secret /home/username/secret ecryptfs '''noauto''','''user''',ecryptfs_fnek_sig='''7c5d3dd8a1b49db0''',ecryptfs_sig='''7c5d3dd8a1b49db0''',ecryptfs_cipher=aes,ecryptfs_key_bytes=32,ecryptfs_unlink_sigs '''0 0'''}} |
||
+ | |||
+ | Some options to note: |
||
+ | * The {{ic|ecryptfs_fnek_sig}} option will be only listed if you enabled filename encryption |
||
+ | * The second last option {{ic|ecryptfs_unlink_sigs}} ensures that the keyring is cleared every time the directory is un-mounted |
||
+ | * The bold options have been added: |
||
+ | ** The {{ic|user}} option enables to mount the directory as a user |
||
+ | ** The {{ic|noauto}} option is important, because otherwise systemd will error trying to mount the entry directly on boot. |
||
+ | * The user mount will default to option {{ic|noexec}}. If you want to have at least executable files in your private directory, you can add {{ic|exec}} to the fstab options. |
||
+ | |||
+ | The setup is now complete and directory should be mountable by the user. |
||
+ | |||
+ | ===== マウント ===== |
||
+ | |||
+ | To mount the encrypted directory as the user, the passphrase must be unwrapped and made available in the user's keyring. Following above section example: |
||
+ | |||
+ | $ ecryptfs-insert-wrapped-passphrase-into-keyring /home/username/.ecryptfs/wrapped-passphrase |
||
+ | Passphrase: |
||
+ | Inserted auth tok with sig [7c5d3dd8a1b49db0] into the user session keyring |
||
+ | |||
+ | Now the directory can be mounted without the mount helper questions: |
||
+ | $ mount -i /home/username/secret |
||
+ | |||
+ | and files be placed into the {{ic|secret}} directory. The above two steps are necessary every time to mount the directory manually. |
||
+ | |||
+ | To unmount it again: |
||
+ | |||
+ | $ umount /home/username/secret |
||
+ | |||
+ | To finalize, the preliminary passphrase to wrap the encryption passphrase may be changed: |
||
+ | $ ecryptfs-rewrap-passphrase /home/username/.ecryptfs/wrapped-passphrase |
||
+ | Old wrapping passphrase: |
||
+ | New wrapping passphrase: |
||
+ | New wrapping passphrase (again): |
||
+ | |||
+ | The un-mounting should also clear the keyring, to check the user's keyring or clear it manually: |
||
+ | $ keyctl list @u |
||
+ | $ keyctl clear @u |
||
+ | |||
+ | {{Note|One should remember that {{ic|/etc/fstab}} is for system-wide partitions only and should not generally be used for user-specific mounts}} |
||
+ | |||
+ | ===== 自動マウント ===== |
||
+ | |||
+ | Different methods can be employed to automount the previously defined user-mount in {{ic|/etc/fstab}} on login. As a first general step, follow point (1) and (2) of [[#Auto-mounting]]. |
||
+ | |||
+ | Then, if you login via console, a simple way is to specify the [[#Mounting_2|user-interactive]] ''mount'' and ''umount'' in the user's shell configuration files, for example [[Bash#Configuration files]]. |
||
+ | |||
+ | Another method is to automount the eCryptfs directory on user login using [[pam_mount]]. To configure this method, add the following lines to {{ic|/etc/security/pam_mount.conf.xml}}: |
||
+ | |||
+ | <luserconf name=".pam_mount.conf.xml" /> |
||
+ | <mntoptions require="" /> <!-- Default required mount options are ; this clears them --> |
||
+ | <lclmount>mount -i %(VOLUME) "%(before=\"-o\" OPTIONS)"</lclmount> <!-- --> |
||
+ | |||
+ | Please prefer writing manually these lines instead of simply copy/pasting them (especially the lclmount line), otherwise you might get some corrupted characters. |
||
+ | Explanation: |
||
+ | * the first line indicates where the user-based configuration file is located (here {{ic|~/.pam_mount.conf.xml}}) |
||
+ | * the second line overwrites the default required mount options which are unnecessary ("nosuid,nodev") |
||
+ | * the last line indicates which mount command to run (eCryptfs needs the {{Ic|-i}} switch). |
||
+ | |||
+ | Then set the volume definition, preferably to {{ic|~/.pam_mount.conf.xml}}: |
||
+ | <pam_mount> |
||
+ | <volume noroot="1" fstype="ecryptfs" path="/home/user/.secret/" mountpoint="/home/user/secret/"/> |
||
+ | </pam_mount> |
||
+ | |||
+ | "noroot" is needed because the encryption key will be added to the user's keyring. |
||
+ | |||
+ | Finally, edit {{ic|/etc/pam.d/login}} as described in [[pam_mount]]'s article. |
||
+ | |||
+ | ====== 任意のステップ ====== |
||
+ | |||
+ | To avoid wasting time needlessly unwrapping the passphrase you can create a script that will check ''pmvarrun'' to see the number of open sessions: |
||
+ | #!/bin/sh |
||
+ | # |
||
+ | # /usr/local/bin/doecryptfs |
||
+ | |||
+ | exit $(/usr/sbin/pmvarrun -u$PAM_USER -o0) |
||
+ | |||
+ | With the following line added before the eCryptfs unwrap module in your PAM stack: |
||
+ | auth [success=ignore default=1] pam_exec.so quiet /usr/local/bin/doecryptfs |
||
+ | auth required pam_ecryptfs.so unwrap |
||
+ | The article suggests adding these to {{ic|/etc/pam.d/login}}, but the changes will need to be added to all other places you login, such as {{ic|/etc/pam.d/kde}}. |
||
+ | |||
+ | == 使用方法 == |
||
+ | |||
+ | === 暗号化ディレクトリにシンボリックリンクを作成 === |
||
+ | |||
+ | Besides using your private directory as storage for sensitive files, and private data, you can also use it to protect application data. [[Firefox]] for example has an internal password manager, but the browsing history and cache can also be sensitive. Protecting it is easy: |
||
+ | $ mv ~/.mozilla ~/Private/mozilla |
||
+ | $ ln -s ~/Private/mozilla ~/.mozilla |
||
+ | |||
+ | === 暗号化の解除 === |
||
+ | |||
+ | There are no special steps involved, if you want to remove your private directory. Make sure it is un-mounted and delete the respective lower directory (e.g. {{ic|~/.Private}}), along with all the encrypted files. After also removing the related encryption signatures and configuration in {{ic|~/.ecryptfs}}, all is gone. |
||
+ | |||
+ | If you were [[#Using the Ubuntu tools]] to setup a single directory encryption, you can directly follow the steps detailed by: |
||
+ | |||
+ | $ ecryptfs-setup-private --undo |
||
+ | |||
+ | and follow the instructions. |
||
+ | |||
+ | === バックアップ === |
||
+ | |||
+ | If you want to move a file out of the private directory just move it to the new destination while {{ic|~/Private}} is mounted. |
||
+ | |||
+ | With eCryptfs the cryptographic metadata is stored in the header of the files. Setup variants explained in this article separate the directory with encrypted data from the mount point. The unencrypted mount point is fully transparent and available for a backup. Obviously this has to be considered for automated backups, if one has to avoid leaking sensitive unencrypted data into a backup. |
||
+ | |||
+ | You can do backups, or incremental backups, of the encrypted (e.g. {{ic|~/.Private}}) directory, treating it like any other directory. |
||
+ | |||
+ | Further points to note: |
||
+ | |||
+ | * If you used the Ubuntu tools for [[#Encrypting a home directory]], be aware the location of the lower directory with the encrypted files is ''outside'' the regular user's {{ic|$HOME}} at {{ic|/home/.ecryptfs/$USER/.Private}}. |
||
+ | |||
+ | * It should be ensured to include the eCryptfs setup files (located in {{ic|~/.ecryptfs}} usually) into the regular or a separate backup. |
||
+ | |||
+ | * If you use special filesystem mount options, for example {{ic|ecryptfs_xattr}}, do extra checks on restore integrity. |
||
+ | |||
+ | == 参照 == |
||
+ | |||
+ | * [http://ecryptfs.org/documentation.html eCryptfs] - Man ページとプロジェクトホーム |
||
+ | * [https://defuse.ca/audits/ecryptfs.htm Security audit] of eCryptfs by Taylor Hornby (2014年1月22日) |
||
+ | * [http://sysphere.org/~anrxc/j/articles/ecryptfs/index.html eCryptfs and $HOME] by Adrian C. (anrxc) - eCryptfs のインストールと使用方法に関する記事 |
||
+ | * [http://www.chromium.org/chromium-os/chromiumos-design-docs/protecting-cached-user-data Chromium data protection] (2009年11月) - Chromium OS の暗号化オプションに関するドキュメントですが、eCryptfs の使い方についても触れています |
||
+ | * [http://ecryptfs.sourceforge.net/ecryptfs.pdf eCryptfs design] by Michael Halcrow (2005年5月) - Original design document detailing and discussing eCryptfs |
2015年12月12日 (土) 21:43時点における版
関連記事
この記事では eCryptfs の基本的な使い方を説明します。プライベートな暗号化ディレクトリを $HOME
ディレクトリに作成して機密ファイルや個人情報を保存する方法を解説していきます。
ブロックデバイスの暗号化レイヤーを提供する dm-crypt とは異なり eCryptfs はファイルシステムそのものです – スタック暗号化ファイルシステム になります。その違いについては この表 やディスク暗号化#比較表を参照してください。大きな特徴として既存のファイルシステム上に暗号化が積み重ねられるという点が挙げられます。eCryptfs はあらゆる既存のディレクトリにマウントすることができ、特別なパーティション (や領域の事前割り当て) を必要としません。
基本
先に述べたように eCryptfs には特殊なパーティションや予約済みの領域をディスク上に配置する必要がありません。代わりに、eCryptfs を既存のディレクトリ上にマウントしてディレクトリを保護することができます。例えば、ユーザーの $HOME
ディレクトリを全体的に保護したり、逆に特定のディレクトリだけを保護したりできます。暗号のメタデータは全てファイルのヘッダの中に保存されます。つまり、暗号化したデータは簡単に移動したり、バックアップ・復元できるということです。他にも利点はありますが、欠点も存在します。例として eCryptfs はパーティション全体を暗号化するのには適していません。また、スワップ領域を eCryptfs で保護することは不可能です (もちろん、Dm-crypt/スワップの暗号化と組み合わせることはできますが)。ディスク暗号化を初めて設定する場合、スワップの暗号化などのポイントはディスク暗号化#準備に書かれています。
eCryptfs を使うなら以下がポイントです:
- スタックファイルシステムとして、eCryptfs ディレクトリのマウントは (スタックされた) 暗号化ディレクトリを他の暗号化されていないマウントポイント (ディレクトリ) マウントすることを意味します。
- ユーザー間で暗号化ディレクトリを共有することができます。ただし、暗号化のパスワードは一つだけなのでパスワードも共有する必要があります。(別々のパスフレーズを使って) 別々に暗号化されたファイルを一つのディレクトリで共有することもできます。
- ドキュメントの中では eCryptfs の専門用語が頻繁に登場します:
- eCryptfs のドキュメントやこの記事では暗号化されるディレクトリは lower (下層) と呼称して暗号化されていないディレクトリは upper (上層) ディレクトリと呼びます。この記事とは無関係ですが、Linux 3.18 で導入された "overlay" ファイルシステム ([2]) では同じ upper/lower という単語をファイルシステムのスタック化について使います。
- mount パスフレーズ (キー) は暗号化されたファイルへのアクセス権限を与えます。つまり暗号化を解除します。eCryptfs は wrapped という言葉を使って mount パスフレーズが暗号的に安全であることを示します。
FEFEK
は File's Encryption key Encryption Key のことです (カーネルドキュメント を参照)。FNEK
は File Name Encryption Key のことです。暗号化ディレクトリに保存されたファイル名を暗号化する鍵になります (任意)。
eCryptfs を使う前に、以下の欠点が障害にならないか確認してください。
欠陥
- 変数がハードコードされている
- eCryptfs の使いやすさは主として ecryptfs-utils パッケージの "Ubuntu tools" に依存しています。決定的な欠点として、ツールの中では多数の変数 (暗号化オプションやディレクトリパス) が決め打ちされています。変数を変更するとなると大変面倒な手動設定が必要ということです。
- ネットワークストレージマウント
- eCryptfs にはネットワークストレージに関する長年の バグ や機能リクエストが存在します。暗号化したディレクトリの中身をネットワークのバックアップストレージに複製することは可能です。しかしながら、ネットワークストレージ上に直接、暗号化ディレクトリを保存してそれをローカルでマウントしたい場合、まずネットワークツール (NFS や Samba など) に対応した解決方法を検索する必要があります。よく分からない場合、EncFS を使うのがベターです。
- スパースファイル
- eCryptfs はスパースファイルを扱うことができません。バグと言われることもありますが、スタックファイルシステムの暗号化として当然そうなるべきことです。例えば、eCryptfs ディレクトリに
truncate -s 1G file.img
で 1GB の暗号化データを作成してファイルシステムに保存する場合、それに対応するリソース (ディスク容量, データのスループット) が必要になります。暗号化しなければ、同じファイルをスパースファイルとして効率的にファイルシステムに保存できます。ブロックデバイスの暗号化はファイルシステムの出力だけを暗号化します。
- 巨大なディレクトリ構造を暗号化するときは予めこのことを考えておく必要があります。大抵の場合、スパースファイルを使えないことが致命的な問題になることはありません。(eCryptfs の標準の
.Private
ディレクトリではなく) 暗号化を施さない.Public
ディレクトリにスパースファイルを保存する方法と、.Public
で dm-crypt' のコンテナを使う方法があります。
セットアップ例の概要
The following #Setup & mounting section describes alternatives using eCryptfs to encrypt a data directory. The alternatives start with #Using the Ubuntu tools, which make eCryptfs usage particularly easy and also safe against user errors. This also applies to #Encrypting a home directory with the tools. During setup, instructions are given on the console by the scripts. The #Using ecryptfs-simple section then introduces an alternative package to aide using eCryptfs. The #Manual setup section then describes the setup using the ecryptfs
filesystem directly. The first subsection (#With ecryptfs-utils) still uses one more script and is suggested to read to familiarize with the setup of the manual options before using them #Without ecryptfs-utils.
The alternatives include
- the setup step for the encrypted directory structures
- the setup to mount, unmount the directory at runtime manually and/or automatically at user login
Each of the described alternative examples can be removed after setup very easily, so do not refrain from testing which suits your needs best.
セットアップ & マウント
eCryptfs はバージョン 2.6.19 から Linux に含まれています。ただし eCryptfs を使うにはユーザースペースツールが必要になります。公式リポジトリの ecryptfs-utils パッケージに入っています。
パッケージをインストールしたら ecryptfs
モジュールをロードしてからセットアップに進みます:
# modprobe ecryptfs
セットアップを始める前に、eCryptfs のドキュメントを確認してください。素晴らしい マニュアルページ が付属しています。
Ubuntu のツールを使う
Most of the user-friendly convenience tools installed by the ecryptfs-utils package assume a very specific eCryptfs setup, namely the one that is officially used by Ubuntu (where it can be selected as an option during distro installation). Unfortunately, these choices are not just default options but are actually hard-coded in the tools. If this set-up does not suit your needs, then you can not use the convenience tools and will have to follow the steps at #Manual setup instead.
The set-up used by these tools is as follows:
- each user can have only one encrypted directory that is managed by these tools:
- either full
$HOME
directory encryption, or - a single encrypted data directory (by default
~/Private/
, but this can be customized).
- either full
- the lower directory for each user is always
~/.Private/
(in the case of full home dir encryption, this will be a symlink to the actual location at/home/.ecryptfs/$USER/.Private/
) - the encryption options used are:
- cipher: AES
- key length: 16 bytes (128 bits)
- key management scheme: passphrase
- plaintext passthrough: enabled
- the configuration / control info for the encrypted directory is stored in a bunch of files at
~/.ecryptfs/
:
(in the case of full home dir encryption, this will be a symlink to the actual location at/home/.ecryptfs/$USER/.ecryptfs/
)Private.mnt
[plain text file] - contains the path where the upper directory should be mounted (e.g./home/lucy
or/home/lucy/Private
)Private.sig
[plain text file] - contains the signature used to identify the mount passphrase in the kernel keyringwrapped-passphrase
[binary file] - the mount passphrase, encrypted with the login passphraseauto-mount
,auto-umount
[empty files] - if they exist, thepam_ecryptfs.so
module will (assuming it is loaded) automatically mount/unmount this encrypted directory when the user logs in/out
データディレクトリの暗号化
For a full $HOME
directory encryption see #Encrypting a home directory
Before the data directory encryption is setup, decide whether it should later be mounted manually or automatically with the user log-in.
To encrypt a single data directory as a user and mount it manually later, run:
$ ecryptfs-setup-private --nopwcheck --noautomount
and follow the instructions. The option --nopwcheck
enables you to choose a passphrase different to the user login passphrase and the option --noautomount
is self-explanatory. So, if you want to setup the encrypted directory automatically on log-in later, just leave out both options right away.
The script will automatically create the ~/.Private/
and ~/.ecryptfs/
directory structures as described in the box above. It will also ask for two passphrases:
- login passphrase
- This is the password you will have to enter each time you want to mount the encrypted directory. If you want auto-mounting on login to work, it has to be the same password you use to login to your user account.
- mount passphrase
- This is used to derive the actual file encryption master key. Thus, you should not enter a custom one unless you know what you are doing - instead press Enter to let it auto-generate a secure random one. It will be encrypted using the login passphrase and stored in this encrypted form in
~/.ecryptfs/wrapped-passphrase
. Later it will automatically be decrypted ("unwrapped") again in RAM when needed, so you never have to enter it manually. Make sure this file does not get lost, otherwise you can never access your encrypted folder again! You may want to runecryptfs-unwrap-passphrase
to see the mount passphrase in unencrypted form, write it down on a piece of paper, and keep it in a safe (or similar), so you can use it to recover your encrypted data in case the wrapped-passphrase file is accidentally lost/corrupted or in case you forget the login passphrase.
The mount point ("upper directory") for the encrypted folder will be at ~/Private
by default, however you can manually change this right after the setup command has finished running, by doing:
$ mv ~/Private /path/to/new/folder $ echo /path/to/new/folder > ~/.ecryptfs/Private.mnt
To actually use your encrypted folder, you will have to mount it - see #Mounting below.
ホームディレクトリの暗号化
The following wrapper script will set up an encrypted $HOME
directory for a user and take care of migrating any existing files they have in their not yet encrypted home directory. Ensure that the user in question owns no processes and is logged out. You also need to ensure that you have rsync and lsof installed. Once the prerequisites have been met, run:
# ecryptfs-migrate-home -u username
and follow the instructions. After the wrapper script is complete, follow the instructions for auto-mounting - see #Auto-mounting below. It is imperative that the user logs in before the next reboot, to complete the process.
マウント
手動
ラッパーを実行:
$ ecryptfs-mount-private
後はパスフレーズを入力するだけで上述の上層ディレクトリである ~/Private
に暗号化ディレクトリをマウントできます。
同じように、以下を実行するとアンマウントされます:
$ ecryptfs-umount-private
The tools include another script that can be very handy to access an encrypted .Private
data or home directory. Executing ecryptfs-recover-private
as root will search the system (or an optional specific path) for the directory, interactively query the passphrase for it and mount the directory. It can, for example, be used from a live-CD or different system to access the encrypted data in case of a recovery. Note that if booting from an Arch Linux ISO you must first install the ecryptfs-utils to it. Further, it will only be able to mount .Private
directories created with the Ubuntu tools.
自動マウント
The default way to auto-mount an encrypted directory is via PAM. See man pam_ecryptfs
and - for more details - 'PAM MODULE' in:
/usr/share/doc/ecryptfs-utils/README
For auto-mounting it is required that the passphrase to access the encrypted directory is synchronised with the user log-in.
The following steps set it up:
1. Check if ~/.ecryptfs/auto-mount
, ~/.ecryptfs/auto-umount
and ~/.ecryptfs/wrapped-passphrase
exist (these are automatically created by ecryptfs-setup-private).
2. Add ecryptfs to the pam-stack exactly as following to allow transparent unwrapping of the passphrase on login:
Open /etc/pam.d/system-auth
and after the line containing auth required pam_unix.so
add:
auth required pam_ecryptfs.so unwrap
Next, above the line containing password required pam_unix.so
insert:
password optional pam_ecryptfs.so
And finally, after the line session required pam_unix.so
add:
session optional pam_ecryptfs.so
3. Re-login and check output of mount which should now contain a mountpoint, e.g.:
/home/$USER/.Private on /home/$USER/Private type ecryptfs (...)
for the user's encrypted directory. It should be perfectly readable at ~$HOME/Private/
.
The latter should be automatically unmounted and made unavailable when the user logs off.
ecryptfs-simple を使う
EncFS と同じように任意のディレクトリをマウントすることだけに eCryptfs を使う場合 ecryptfs-simple を使って下さい。ecryptfs-simple は root 権限を必要とせず /etc/fstab
にエントリを書く必要もありません。さらに ~/.Private
などのディレクトリにハードコードもされていません。ecryptfs-simpleAUR や Xyne のリポジトリ からパッケージをインストールできます。
名は体を表すとおり、使用方法はシンプルです:
# simple mounting ecryptfs-simple /path/to/foo /path/to/bar
# automatic mounting: prompts for options on the first mount of a directory then reloads them next time ecryptfs-simple -a /path/to/foo /path/to/bar
# unmounting by source directory ecryptfs-simple -u /path/to/foo
# unmounting by mountpoint ecryptfs-simple -u /path/to/bar
手動セットアップ
The following details instructions to set up eCryptfs encrypted directories manually. The first section still relies on one extra script from the ecryptfs-utils package. It may be an easier start and can be tried without any root rights. The second then sets up an encrypted directory with other encryption options than the default tools.
ecryptfs-utils を使う
Alternatively to using the scripts ecryptfs-setup-private
and ecryptfs-mount-private
to setup and mount eCryptfs, the same can be done directly with the binaries (which those scripts use) ecryptfs-add-passphrase
and mount.ecryptfs_private
from the ecryptfs-utils package. Those binaries require no root privileges to work by default.
First choose an ALIAS as you like. Through this section, ALIAS will be secret
. Create the required directories/files:
$ mkdir ~/.secret ~/secret ~/.ecryptfs $ touch ~/.ecryptfs/secret.conf ~/.ecryptfs/secret.sig
The ~/.secret
directory will hold the encrypted data. The ~/secret
directory is the mount point where ~/.secret
will be mounted as an ecryptfs filesystem.
In the next command, replace USER with the name of the current user's home directory. Note that you should write full paths to ~/.ecryptfs/secret.conf
. Its format looks like the one in /etc/fstab
without the mount options:
$ echo "/home/USER/.secret /home/USER/secret ecryptfs" > ~/.ecryptfs/secret.conf
A mount passphrase must be added to the keyring:
$ ecryptfs-add-passphrase Passphrase: Inserted auth tok with sig [78c6f0645fe62da0] into the user session keyring
Write the output signature (ecryptfs_sig
) from the previous command to ~/.ecryptfs/secret.sig
:
$ echo 78c6f0645fe62da0 > ~/.ecryptfs/secret.sig
A second passphrase for filename encryption may be used. If you choose so, add it to the keyring:
$ ecryptfs-add-passphrase Passphrase: Inserted auth tok with sig [326a6d3e2a5d444a] into the user session keyring
If you run the command above, append its output signature (ecryptfs_fnek_sig
) to ~/.ecryptfs/secret.sig
:
$ echo 326a6d3e2a5d444a >> ~/.ecryptfs/secret.sig
Finally, to mount ~/.secret
on ~/secret
:
$ mount.ecryptfs_private secret
An eCryptfs filesystem will be mounted with the following options:
rw,nosuid,nodev,relatime,ecryptfs_fnek_sig=326a6d3e2a5d444a,ecryptfs_sig=78c6f0645fe62da0,ecryptfs_cipher=aes,ecryptfs_key_bytes=16,ecryptfs_unlink_sigs
Except for ecryptfs_sig
and ecryptfs_fnek_sig
, the options are hard-coded. ecryptfs_fnek_sig
will exist only if you choose filename encryption.
To unmount ~/.secret
:
$ umount.ecryptfs_private secret
ecryptfs-utils を使う
The ecryptfs-utils package is distributed with a few helper scripts which will help you with key management and similar tasks. If one wants, for example, make a choice about the encryption cipher, some of those scripts cannot be used. In this section we setup an encrypted data directory diverting from those defaults.
First create your private directories, in this example we will call them analogous to the previous section: secret
$ mkdir -m 700 /home/username/{.secret,.ecryptfs} $ mkdir -m 500 /home/username/secret
To summarize:
- Actual encrypted data will be stored in the lower
~/.secret
directory - While mounted, decrypted data will be available in
~/secret
directory- While not mounted nothing can be written to this directory
- While mounted it has the same permissions as the lower directory
Second we create the mount-passphrase ("file encryption key, encryption key", or fekek) for the directory. It has to be very secure and cannot be changed easily. The ecryptfs-setup-private script offers the option to generate it from /dev/urandom
. In the following we do a generation similar to the source and then use ecryptfs-wrap-passphrase to wrap it with an extra password ("Arch"):
$ printf "%s\n%s" $(od -x -N 100 --width=30 /dev/random | head -n 1 | sed "s/^0000000//" | sed "s/\s*//g") "Arch" | ecryptfs-wrap-passphrase /home/username/.ecryptfs/wrapped-passphrase
The advantages of the above step are: the mount passphrase is generated from a random source and secured by extra hashing before it is stored on disk. Further, the wrap-passphrase can be changed later.
Next, we test the passphrase by loading it into the kernel keyring:
$ printf "%s" "Arch" | ecryptfs-insert-wrapped-passphrase-into-keyring /home/username/.ecryptfs/wrapped-passphrase - Inserted auth tok with sig [7c5d3dd8a1b49db0] into the user session keyring
and manually copy the signature into the configuration:
$ echo "7c5d3dd8a1b49db0" > ~/.ecryptfs/secret.sig
Now we continue to setup the encryption options for the directory and prepare an user-mountable entry for /etc/fstab
. If you already know the eCryptfs options to use in it, you can skip the following mount and create an entry with the above signature already.
The mount.ecryptfs command needs root and does not allow for piping the passphrase unfortunately. The mount helper will ask questions about the options we want to choose ("Key type": passphrase - choose any, we only do this to generate the options to use), but let it mount:
# mount -t ecryptfs /home/username/.secret /home/username/secret Passphrase: yes Cipher: aes Key byte: 32 Plaintext passtrough: no Filename encryption: no Add signature to cache: yes
To summarize the parameters:
- The above chosen
32
"key bytes" result in a 256 bit AES encryption (the helper scripts are hard-coded to AES with 128 bit). - Plaintext passtrough enables to store and work with un-encrypted files stored in the lower directory.
- In eCryptfs terms the key used to protect filenames is known as "filename encryption key", or fnek
- fekek and fnek can be the same key or different ones at choice
To create the mount point for the user in fstab, find the current mount and copy it. For example (XY
are placeholders here):
# mount
/home/username/.secret on /home/username/secret type ecryptfs (... ecryptfs_fnek_sig=XY,ecryptfs_sig=XY,ecryptfs_cipher=aes,ecryptfs_key_bytes=32,ecryptfs_unlink_sigs, user)
Or, alternatively, append it into /etc/fstab
to edit it:
# mount | grep secret >> /etc/fstab
Before continuing, we can already un-mount the temporary mount we used to generate the options:
# umount /home/username/secret
Now the mount line has to be edited into the correct format, the mount options nosuid,nodev,noexec,relatime
before the first ecryptfs option are default and can be left out. But what we need to add is the correct signatures for the passphrases to replace the ones of the current mount:
# cat /home/username/.ecryptfs/secret.sig 7c5d3dd8a1b49db0
We also need to add the options user
and noauto
. After the edit, the entry will look similar to (bold entries added):
/etc/fstab
/home/username/.secret /home/username/secret ecryptfs noauto,user,ecryptfs_fnek_sig=7c5d3dd8a1b49db0,ecryptfs_sig=7c5d3dd8a1b49db0,ecryptfs_cipher=aes,ecryptfs_key_bytes=32,ecryptfs_unlink_sigs 0 0
Some options to note:
- The
ecryptfs_fnek_sig
option will be only listed if you enabled filename encryption - The second last option
ecryptfs_unlink_sigs
ensures that the keyring is cleared every time the directory is un-mounted - The bold options have been added:
- The
user
option enables to mount the directory as a user - The
noauto
option is important, because otherwise systemd will error trying to mount the entry directly on boot.
- The
- The user mount will default to option
noexec
. If you want to have at least executable files in your private directory, you can addexec
to the fstab options.
The setup is now complete and directory should be mountable by the user.
マウント
To mount the encrypted directory as the user, the passphrase must be unwrapped and made available in the user's keyring. Following above section example:
$ ecryptfs-insert-wrapped-passphrase-into-keyring /home/username/.ecryptfs/wrapped-passphrase Passphrase: Inserted auth tok with sig [7c5d3dd8a1b49db0] into the user session keyring
Now the directory can be mounted without the mount helper questions:
$ mount -i /home/username/secret
and files be placed into the secret
directory. The above two steps are necessary every time to mount the directory manually.
To unmount it again:
$ umount /home/username/secret
To finalize, the preliminary passphrase to wrap the encryption passphrase may be changed:
$ ecryptfs-rewrap-passphrase /home/username/.ecryptfs/wrapped-passphrase Old wrapping passphrase: New wrapping passphrase: New wrapping passphrase (again):
The un-mounting should also clear the keyring, to check the user's keyring or clear it manually:
$ keyctl list @u $ keyctl clear @u
自動マウント
Different methods can be employed to automount the previously defined user-mount in /etc/fstab
on login. As a first general step, follow point (1) and (2) of #Auto-mounting.
Then, if you login via console, a simple way is to specify the user-interactive mount and umount in the user's shell configuration files, for example Bash#Configuration files.
Another method is to automount the eCryptfs directory on user login using pam_mount. To configure this method, add the following lines to /etc/security/pam_mount.conf.xml
:
<luserconf name=".pam_mount.conf.xml" /> <mntoptions require="" /> <lclmount>mount -i %(VOLUME) "%(before=\"-o\" OPTIONS)"</lclmount>
Please prefer writing manually these lines instead of simply copy/pasting them (especially the lclmount line), otherwise you might get some corrupted characters. Explanation:
- the first line indicates where the user-based configuration file is located (here
~/.pam_mount.conf.xml
) - the second line overwrites the default required mount options which are unnecessary ("nosuid,nodev")
- the last line indicates which mount command to run (eCryptfs needs the
-i
switch).
Then set the volume definition, preferably to ~/.pam_mount.conf.xml
:
<pam_mount> <volume noroot="1" fstype="ecryptfs" path="/home/user/.secret/" mountpoint="/home/user/secret/"/> </pam_mount>
"noroot" is needed because the encryption key will be added to the user's keyring.
Finally, edit /etc/pam.d/login
as described in pam_mount's article.
任意のステップ
To avoid wasting time needlessly unwrapping the passphrase you can create a script that will check pmvarrun to see the number of open sessions:
#!/bin/sh # # /usr/local/bin/doecryptfs exit $(/usr/sbin/pmvarrun -u$PAM_USER -o0)
With the following line added before the eCryptfs unwrap module in your PAM stack:
auth [success=ignore default=1] pam_exec.so quiet /usr/local/bin/doecryptfs auth required pam_ecryptfs.so unwrap
The article suggests adding these to /etc/pam.d/login
, but the changes will need to be added to all other places you login, such as /etc/pam.d/kde
.
使用方法
暗号化ディレクトリにシンボリックリンクを作成
Besides using your private directory as storage for sensitive files, and private data, you can also use it to protect application data. Firefox for example has an internal password manager, but the browsing history and cache can also be sensitive. Protecting it is easy:
$ mv ~/.mozilla ~/Private/mozilla $ ln -s ~/Private/mozilla ~/.mozilla
暗号化の解除
There are no special steps involved, if you want to remove your private directory. Make sure it is un-mounted and delete the respective lower directory (e.g. ~/.Private
), along with all the encrypted files. After also removing the related encryption signatures and configuration in ~/.ecryptfs
, all is gone.
If you were #Using the Ubuntu tools to setup a single directory encryption, you can directly follow the steps detailed by:
$ ecryptfs-setup-private --undo
and follow the instructions.
バックアップ
If you want to move a file out of the private directory just move it to the new destination while ~/Private
is mounted.
With eCryptfs the cryptographic metadata is stored in the header of the files. Setup variants explained in this article separate the directory with encrypted data from the mount point. The unencrypted mount point is fully transparent and available for a backup. Obviously this has to be considered for automated backups, if one has to avoid leaking sensitive unencrypted data into a backup.
You can do backups, or incremental backups, of the encrypted (e.g. ~/.Private
) directory, treating it like any other directory.
Further points to note:
- If you used the Ubuntu tools for #Encrypting a home directory, be aware the location of the lower directory with the encrypted files is outside the regular user's
$HOME
at/home/.ecryptfs/$USER/.Private
.
- It should be ensured to include the eCryptfs setup files (located in
~/.ecryptfs
usually) into the regular or a separate backup.
- If you use special filesystem mount options, for example
ecryptfs_xattr
, do extra checks on restore integrity.
参照
- eCryptfs - Man ページとプロジェクトホーム
- Security audit of eCryptfs by Taylor Hornby (2014年1月22日)
- eCryptfs and $HOME by Adrian C. (anrxc) - eCryptfs のインストールと使用方法に関する記事
- Chromium data protection (2009年11月) - Chromium OS の暗号化オプションに関するドキュメントですが、eCryptfs の使い方についても触れています
- eCryptfs design by Michael Halcrow (2005年5月) - Original design document detailing and discussing eCryptfs