LUKS(Linux Unified Key Setup)爲Linux硬盤分區加密提供了一種標準,它不僅能通用於不同的Linux發行版本,還支持多用戶/口令。因爲它的加密密鑰獨立於口令,所以如果口令失密,我們可以迅速改變口令而無需重新加密真個硬盤。通過提供一個標準的磁盤上的格式,它不僅方便之間分佈的兼容性,而且還提供了多個用戶密碼的安全管理。必須首先對加密的捲進行解密,才能掛載其中的文件系統。
- 格式化LUKS分區
- [[email protected] ~]# cryptsetup luksFormat /dev/vda8 //將分區進行LUKS格式(變成LUKS分區)
- WARNING!
- ========
- This will overwrite data on /dev/vda8 irrevocably.
- Are you sure? (Type uppercase yes): YES //輸入大寫的YES
- Enter LUKS passphrase: //輸入兩次密碼
- Verify passphrase:
- 映射分區
- [[email protected] ~]# cryptsetup luksOpen /dev/vda8 luks_test //打開LUKS分區,將在/dev/mapper/目錄中生成一個luks_test的文件
- Enter passphrase for /dev/vda8: //必須輸入luks密碼才能打開LUKS分區
- 格式化、掛載、使用分區
- [[email protected] ~]# mkfs.ext4 /dev/mapper/luks_test
- [[email protected] ~]# mount /dev/mapper/luks_test /luks/
- 關閉映射,先卸載後關閉
- [[email protected] ~]# umount /luks/
- [[email protected] ~]# cryptsetup luksClose luks_test //關閉LUKS分區
- [[email protected] ~]# mount /dev/vda8 /luks/ //無法直接掛載/dev/vda8分區
- mount: unknown filesystem type 'crypto_LUKS'
- 實現開機自動掛載LUKS分區:
- [[email protected] ~]# dd if=/dev/urandom of=keyfile bs=1k count=4
- 4+0 records in
- 4+0 records out
- 4096 bytes (4.1 kB) copied, 0.00206882 s, 2.0 MB/s
- [[email protected] ~]# cryptsetup luksAddKey /dev/vda8 keyfile
- Enter any passphrase:
- [[email protected] ~]# vi /etc/crypttab
- name /dev/vda8 /root/keyfile luks
- [[email protected] ~]# vi /etc/fstab
- /dev/mapper/name /luks ext4 _netdev 0 0
- 添加/移除/修改LUKS密碼
- [[email protected] ~]# cryptsetup luksAddKey /dev/vda8
- Enter any passphrase:
- Enter new passphrase for key slot:
- Verify passphrase:
- [[email protected] ~]# cryptsetup luksRemoveKey /dev/vda8
- Enter LUKS passphrase to be deleted:
- [[email protected] ~]# cryptsetup luksAddKey /dev/vda8 keyfile
- Enter any passphrase: