Quantcast
Channel: Bashタグが付けられた新着記事 - Qiita
Viewing all articles
Browse latest Browse all 2817

ブロックデバイスを暗号化する(cryptsetup)

$
0
0

dm-crypt(カーネルの暗号化機能)を利用する

dm-cryptを利用するツールとしてcryptsetupとcryptmountがある。
今回はcryptsetupを利用してブロックデバイスを暗号化する。

LUKS(Linux Unified Key Setup)を利用する

LUKSはLinuxの暗号化ファイルシステムの標準規格

# ブロックデバイスを暗号化する
cryptsetup luksFormat /dev/sdb1

WARNING!
========
This will overwrite data on /dev/sdb1 irrevocably.

Are you sure? (Type uppercase yes): YES
Enter passphrase for /dev/sdb1: パスワードを作成
Verify passphrase: パスワードを再入力
# パスワードが設定されたか確認
cryptsetup luksDump /dev/sdb1
# 作成されている
Key Slot 0: ENABLED
# 作成済みの暗号化パーティションを名前をつけて開く
cryptsetup luksOpen /dev/sdb1 lukstest
Enter passphrase for /dev/sdb1: 指定したパスワード
# ファイルシステムの作成
mkfs -t xfs /dev/mapper/lukstest
meta-data=/dev/mapper/lukstest   isize=512    agcount=4, agsize=196480 blks
         =sectsz=512   attr=2, projid32bit=1
         =crc=1        finobt=0, sparse=0
data     =bsize=4096   blocks=785920, imaxpct=25
         =sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal log           bsize=4096   blocks=2560, version=2
         =sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
# マウントする
mount /dev/mapper/lukstest /home/
# 確認df
Filesystem              1K-blocks    Used Available Use% Mounted on
devtmpfs                   495744       0    495744   0% /dev
tmpfs                      507380       0    507380   0% /dev/shm
tmpfs                      507380    6852    500528   2% /run
tmpfs                      507380       0    507380   0% /sys/fs/cgroup
/dev/mapper/centos-root   6486016 1504808   4981208  24% /
/dev/sda1                 1038336  196308    842028  19% /boot
tmpfs                      101480       0    101480   0% /run/user/0
/dev/mapper/lukstest      3133440   32992   3100448   2% /home
# 起動時にマウントするようにパスワードファイルを作成するdd bs=512 count=4 if=/dev/urandom of=/etc/lukstestkey
4+0 records in
4+0 records out
2048 bytes (2.0 kB) copied, 0.000366841 s, 5.6 MB/s
# 暗号化したパーティションにパスワードを追加
cryptsetup luksAddKey /dev/sdb1 /etc/lukstestkey
Enter any existing passphrase: 作成時に指定したパスワード

起動時にマウントするように設定ファイルに追記する

/etc/crypttab
lukstest  /dev/sdb1  /etc/lukstestkeyluks,timeout=180
/etc/fstab
/dev/mapper/lukstest /homexfsdefaults00

Viewing all articles
Browse latest Browse all 2817

Trending Articles