LUKS(Linux Unified Key Setup)為Linux硬碟分區加密提供了一種标準,它不僅能通用于不同的Linux發行版本,還支援多使用者/密碼。因為它的加密密鑰獨立于密碼,是以如果密碼失密,我們可以迅速改變密碼而無需重新加密真個硬碟。通過提供一個标準的磁盤上的格式,它不僅友善之間分布的相容性,而且還提供了多個使用者密碼的安全管理。必須首先對加密的卷進行解密,才能挂載其中的檔案系統。
工具:cryptsetup(預設已經安裝)
常用參數:luksFormat、luksOpen、luksClose、luksAddKey
使用cryptsetup對分區進行了加密後,這個分區就不再允許直接挂載。LUKS也是一種基于device mapper 機制的加密方案。如果要使用這個分區,必須對這個分區做一個映射,映射到/dev/mapper這個目錄裡去,我們隻能挂載這個映射才能使用。然而做映射的時候是需要輸入解密密碼的。
注:要解除加密需要備份分區内的檔案再重新格式化LUKS分區
Crypsetup工具加密的特點:
Ø加密後不能直接挂載
Ø加密後硬碟丢失也不用擔心資料被盜
Ø加密後必須做映射才能挂載
格式化LUKS分區
[root@rhel6 ~]# 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:
映射分區
[root@rhel6 ~]# cryptsetup luksOpen /dev/vda8 luks_test //打開LUKS分區,将在/dev/mapper/目錄中生成一個luks_test的檔案
Enter passphrase for /dev/vda8: //必須輸入luks密碼才能打開LUKS分區
格式化、挂載、使用分區
[root@rhel6 ~]# mkfs.ext4 /dev/mapper/luks_test
[root@rhel6 ~]# mount /dev/mapper/luks_test /luks/
關閉映射,先解除安裝後關閉
[root@rhel6 ~]# umount /luks/
[root@rhel6 ~]# cryptsetup luksClose luks_test //關閉LUKS分區
[root@rhel6 ~]# mount /dev/vda8 /luks/ //無法直接挂載/dev/vda8分區
mount: unknown filesystem type 'crypto_LUKS'
實作開機自動挂載LUKS分區:
[root@rhel6 ~]# 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
[root@rhel6 ~]# cryptsetup luksAddKey /dev/vda8 keyfile
Enter any passphrase:
[root@rhel6 ~]# vi /etc/crypttab
name /dev/vda8 /root/keyfile luks
[root@rhel6 ~]# vi /etc/fstab
/dev/mapper/name /luks ext4 _netdev 0 0
添加/移除/修改LUKS密碼
[root@rhel6 ~]# cryptsetup luksAddKey /dev/vda8
Enter new passphrase for key slot:
[root@rhel6 ~]# cryptsetup luksRemoveKey /dev/vda8
Enter LUKS passphrase to be deleted:
本文轉自Vnimos51CTO部落格,原文連結:http://blog.51cto.com/vnimos/1175883,如需轉載請自行聯系原作者