page counter next up previous contents
Next: LUKS Mapping Up: LUKS 檔案系統加解密 Previous: 前言   Contents   DYWANG_HOME

LUKS 工具

  1. 查看使用的硬碟編號為 /dev/sda,目前 / 根目錄掛載在 /dev/sda3,預計將 /dev/sda2 做 LUKS 加密並掛載成 / 根目錄。
    [root@localhost ~]# lsblk 
    NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
    sda      8:0    0 18.4G  0 disk 
    ├─sda1   8:1    0  400M  0 part /boot
    ├─sda2   8:2    0   10G  0 part 
    ├─sda3   8:3    0    4G  0 part /
    ├─sda4   8:4    0    1K  0 part 
    └─sda5   8:5    0  500M  0 part [SWAP]
    
  2. 查詢提供 LUKS 工具命令的套件為 cryptsetup。
    [root@localhost ~]# yum provides *bin/cryptsetup
    Loaded plugins: fastestmirror, langpacks
    base                                                     | 3.6 kB     00:00     
    extras                                                   | 3.4 kB     00:00     
    updates                                                  | 3.4 kB     00:00     
    (1/4): base/7/x86_64/group_gz                              | 156 kB   00:00     
    (2/4): extras/7/x86_64/primary_db                          | 145 kB   00:00     
    (3/4): updates/7/x86_64/primary_db                         | 4.6 MB   00:05     
    (4/4): base/7/x86_64/primary_db                            | 5.7 MB   00:05     
    Determining fastest mirrors
     * base: ftp.twaren.net
     * extras: ftp.twaren.net
     * updates: ftp.twaren.net
    base/7/x86_64/filelists_db                               | 6.7 MB     00:03     
    cryptsetup-1.7.4-3.el7.x86_64 : A utility for setting up encrypted disks
    Repo        : base
    Matched from:
    Filename    : /usr/sbin/cryptsetup
    
  3. 安裝 cryptsetup 套件。
    [root@localhost ~]# yum install -y cryptsetup
    
  4. 為加強分割區加密強度,格式化前最好先將整個分割區寫入隨機字元,以下為較快速但強度較低的寫入方式。
    [root@localhost ~]# badblocks -c 10240 -s -w -t random -v /dev/sda2
    Checking for bad blocks in read-write mode
    From block 0 to 10485759
    Testing with random pattern: done                                                 
    Reading and comparing: done                                                 
    Pass completed, 0 bad blocks found. (0/0/0 errors)
    
  5. 使用 cryptsetup 對 /dev/sda2 進行 luks 格式化,過程中先回答大寫的 YES,再輸入兩次密碼,密碼必須超過 7 個字元且不能為字典字。
    [root@localhost ~]# cryptsetup luksFormat /dev/sda2
    
    WARNING!
    ========
    This will overwrite data on /dev/sda2 irrevocably.
    
    Are you sure? (Type uppercase yes): YES
    Enter passphrase: 
    Verify passphrase: 
    Password quality check failed:
     The password is shorter than 7 characters
    [root@localhost ~]# cryptsetup luksFormat /dev/sda2
    
    WARNING!
    ========
    This will overwrite data on /dev/sda2 irrevocably.
    
    Are you sure? (Type uppercase yes): YES
    Enter passphrase: 
    Verify passphrase: 
    Password quality check failed:
     The password fails the dictionary check - it is based on a dictionary word
    [root@localhost ~]# cryptsetup luksFormat /dev/sda2
    
    WARNING!
    ========
    This will overwrite data on /dev/sda2 irrevocably.
    
    Are you sure? (Type uppercase yes): YES
    Enter passphrase: 
    Verify passphrase: 
    Password quality check failed:
     The password fails the dictionary check - it is based on a dictionary word
    
  6. 成功進行 /dev/sda2 分割區 LUKS 格式化。
    [root@localhost ~]# cryptsetup luksFormat /dev/sda2
    
    WARNING!
    ========
    This will overwrite data on /dev/sda2 irrevocably.
    
    Are you sure? (Type uppercase yes): YES
    Enter passphrase: ekC82B7XAmv3 
    Verify passphrase: ekC82B7XAmv3
    
  7. 確認 /dev/sda2 是否為 LUKS 格式?沒有錯誤訊息表示正常。
    [root@localhost ~]# cryptsetup isLuks /dev/sda2
    [root@localhost ~]# cryptsetup isLuks /dev/sda2 && echo Success
    Success
    
  8. 使用 luksDump 查看 /dev/sda2 的加密訊息。
    [root@localhost ~]# cryptsetup luksDump /dev/sda2
    LUKS header information for /dev/sda2
    
    Version:		1
    Cipher name:	aes
    Cipher mode:	xts-plain64
    Hash spec:		sha256
    Payload offset:	4096
    MK bits:		256
    MK digest:		75 b9 1e 6c fc 72 6a c0 2a 67 6a db fa df 33 7f 65 a7 c5 3b 
    MK salt:		d8 65 2c b2 f8 43 af f6 30 0b ca 49 01 bf 1c c7 
    				cd 62 7e 60 09 78 c8 5f 4f dc 5b f0 67 89 33 15 
    MK iterations:	89250
    UUID:			b22f30aa-72d7-4523-aa21-dc516da53fc8
    
    Key Slot 0: ENABLED
    	Iterations:				703294
    	Salt:					50 b4 74 b0 1f 07 e0 e5 11 56 ae a7 2c bd 64 a0 
    							ef c6 e6 53 5c 73 5a 57 41 8f e4 38 69 99 2e 25 
    	Key material offset:	8
    	AF stripes:				4000
    Key Slot 1: DISABLED
    Key Slot 2: DISABLED
    Key Slot 3: DISABLED
    Key Slot 4: DISABLED
    Key Slot 5: DISABLED
    Key Slot 6: DISABLED
    Key Slot 7: DISABLED
    



De-Yu Wang 2020-05-14