注意:
- 本教學課程包含在 Oracle 提供的免費實驗室環境中。
- 它會使用 Oracle Cloud Infrastructure 證明資料、租用戶以及區間的範例值。完成實驗室之後,請將這些值取代為您雲端環境特有的值。
在 Oracle Linux 上使用 LUKS 加密磁帶機
簡介
Oracle Linux 包括裝置對應程式加密 (dm-crypt) 和 Linux Unified Key Setup (LUKS) 以處理區塊裝置上的加密。
在此實驗室中,我們將專注於使用 LUKS 加密裝置的前端工具,該裝置使用 Linux Kernel 內附的裝置對應程式支援 dm-crypt 模組。
目標
- 安裝
cryptsetup - 建立加密的磁碟區
- 掛載加密的磁碟區
需求
具有可用磁碟的系統,以及完整修補的 Oracle Linux 安裝。
設定實驗室環境
注意:使用免費實驗室環境時,請參閱 Oracle Linux Lab Basics ,瞭解連線和其他使用指示。
-
如果尚未連接,請開啟終端機並透過 ssh 連線至 ol-node01 執行處理。
ssh oracle@<ip_address_of_instance> -
確認區塊磁碟區存在。
lsblk -f免費實驗室環境的輸出顯示兩個區塊裝置:
sda,其中包含此實驗室所使用的基本作業系統和sdb。使用-f選項,會顯示檔案系統類型 (FSTYPE) 和區塊通用唯一 ID (UUID)。
安裝加密套裝程式
-
如果系統上尚未提供,請安裝
cryptsetup工具。檢查是否已安裝
cryptsetup。sudo dnf list --installed cryptsetup若未安裝,請安裝
cryptsetup。sudo dnf -y install cryptsetup注意:可用實驗室環境已安裝
cryptsetup工具。
使用 LUKS 加密磁碟區
LUKS 和 dm-crypt 可用於區塊裝置、RAID、LVM 實體磁碟區,甚至是交換。加密之後,這些裝置上的資料只能在啟動或掛載時間使用適當的證明資料存取。
免費實驗室環境提供此步驟的預先分割磁碟 /dev/sdb1。
-
加密磁碟。
sudo cryptsetup -y -v luksFormat /dev/sdb1輸入
YES以繼續並提供密碼詞組兩次。密碼片語必須包含 :- 最少 8 個字元
- 1 位數
- 1 個大寫字母
- 1 個特殊字元
- 非字典式字
重要:請記得輸入的密碼,稍後再使用。
範例輸出:
[oracle@ol-node01 ~]$ sudo cryptsetup -y -v luksFormat /dev/sdb1 WARNING! ======== This will overwrite data on /dev/sdb1 irrevocably. Are you sure? (Type 'yes' in capital letters): YES Enter passphrase for /dev/sdb1: Verify passphrase: Key slot 0 created. Command successful. -
開啟加密的磁碟區。
此步驟需要可命名為任何項目的目標。我們使用
mysecrets。sudo cryptsetup -v luksOpen /dev/sdb1 mysecrets輸入要求時在上一個步驟中建立的相同密碼詞組。
範例輸出:
[oracle@ol-node01 ~]$ sudo cryptsetup -v luksOpen /dev/sdb1 mysecrets Enter passphrase for /dev/sdb1: Key slot 0 unlocked. Command successful. -
再次檢查區塊裝置。
lsblk -f裝置
/dev/sdb1現在會將 FSTYPE 顯示為 crypto_LUKS ,並顯示加密裝置磁碟區的對應mysecrets。
格式化加密的磁碟區
將資料新增至加密磁碟區之前,必須先加以格式化。您可以選擇不同的檔案系統,例如 xfs、ext3、ext4 等。
-
建立檔案系統。
sudo mkfs.xfs /dev/mapper/mysecrets
掛載加密的磁碟區
-
建立一個掛載點 。
sudo mkdir -p /u01/my_secret_storage -
掛載磁碟區。
sudo mount -v /dev/mapper/mysecrets /u01/my_secret_storage輸出顯示 SELinux 警告。
範例輸出:
[oracle@ol-node01 ~]$ sudo mount -v /dev/mapper/mysecrets /u01/my_secret_storage/ mount: /u01/my_secret_storage does not contain SELinux labels. You just mounted an file system that supports labels which does not contain labels, onto an SELinux box. It is likely that confined applications will generate AVC messages and not be allowed access to this file system. For more details see restorecon(8) and mount(8). mount: /dev/mapper/mysecrets mounted on /u01/my_secret_storage.這需要重新標示掛載點的 SELinux 安全相關資訊環境。
sudo restorecon -vvRF /u01/my_secret_storage再次執行
mount指令。sudo mount -v -o remount /u01/my_secret_storage -
顯示已掛載的磁碟區。
lsblk範例輸出:
[oracle@ol-node01 ~]$ lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 46.6G 0 disk |-sda1 8:1 0 100M 0 part /boot/efi |-sda2 8:2 0 1G 0 part /boot `-sda3 8:3 0 45.5G 0 part |-ocivolume-root 252:0 0 35.5G 0 lvm / `-ocivolume-oled 252:1 0 10G 0 lvm /var/oled sdb 8:16 0 50G 0 disk `-sdb1 8:17 0 2G 0 part `-mysecrets 252:2 0 2G 0 crypt /u01/my_secret_storage
顯示 LUKS 磁碟區詳細資訊
檢視 LUKS 標頭、資料區段、金鑰槽以及版本資訊。
-
傾印 LUKS 詳細資訊。
sudo cryptsetup luksDump /dev/sdb1範例輸出:
LUKS header information Version: 2 Epoch: 3 Metadata area: 16384 [bytes] Keyslots area: 16744448 [bytes] UUID: 4ccea398-5864-45a9-b274-173c8ebc3356 Label: (no label) Subsystem: (no subsystem) Flags: (no flags) Data segments: 0: crypt offset: 16777216 [bytes] length: (whole device) cipher: aes-xts-plain64 sector: 512 [bytes] Keyslots: 0: luks2 Key: 512 bits Priority: normal Cipher: aes-xts-plain64 Cipher key: 512 bits PBKDF: argon2i Time cost: 10 Memory: 1048576 Threads: 4 Salt: ee d2 c7 5b 05 43 0f 0a 12 60 da b5 87 19 4a 6f 06 57 a2 31 b1 dd bb 60 74 53 95 b2 ca 2f ad 4b AF stripes: 4000 AF hash: sha256 Area offset:32768 [bytes] Area length:258048 [bytes] Digest ID: 0 Tokens: Digests: 0: pbkdf2 Hash: sha256 Iterations: 243628 Salt: 89 6c 8b aa 37 af 58 e9 26 49 c5 e5 db 2d 54 ea f8 7a c2 89 0e ab ed 48 74 a5 23 d7 b0 e6 9c 87 Digest: 4a 2b 25 76 c5 85 1a 6c a9 28 0c ee d0 c7 76 eb e1 4c ee 9c 5b 9a e2 d0 95 6e 1f 6e bb 1b 03 d1
如需其他資訊,請參閱 cryptsetup(8) 線上手冊、Oracle 文件或上游 FAQ 。
其他相關資訊
請參閱其他相關資源:
其他學習資源
探索 docs.oracle.com/learn 上的其他實驗室,或存取 Oracle Learning YouTube 通道上的更多免費學習內容。此外,請造訪 education.oracle.com/learning-explorer 以成為 Oracle Learning Explorer。
如需產品文件,請瀏覽 Oracle Help Center 。
Encrypt Drives using LUKS on Oracle Linux
F60518-01
July 2022
Copyright © 2022, Oracle and/or its affiliates.