歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux教程 >> Red Hat Linux 7 中分區加密技術

Red Hat Linux 7 中分區加密技術

日期:2017/2/28 13:53:58   编辑:Linux教程

一 分區加密簡介
軍工方面重要的保密安全措施技術,國際安全組織采取的一種對磁盤內容加密的解決方案,因為殺毒軟件的後覺性是無法保證安全性更高的領域。所以在機密級別較高的領域采取主動性的安全解決方案,而分區加密是其中一種,其加密算法是運用當今國際最尖端的采用256位軟硬件結合加密算法,除了密碼之外還需要一個u-key, 同時支持256位數據加密,采用先進的數據隱藏技術、32位嵌入式微處理器和"真"隨機數發生器,確保了分區加密的安全性和密鑰的唯一性。

二 實驗環境及內容
環境: Red Hat Linux 7

內容: 先分出一個分區,然後現在上面加密,然後再鋪上文件系統,這樣做的好處就是,當那個密碼破解失敗,那麼文件內容也就會毀壞,能有效地保護我們的隱私內容。

三 具體操作
因為我們是做實驗,所以首先先建立幾個新的分區,
1>用命令 cat /proc/partitions 查看
如下:

[root@localhost Desktop]# cat /proc/partitions
major minor #blocks name

253 0 10485760 vda
253 1 10484142 vda1
253 16 10485760 vdb
7 0 3655680 loop0
接下來我們在 /dev/vdb 劃分一個新的分區:
用命令 fdisk /dev/vdb 然後根據裡面的提示劃分一個:
在用cat /proc/partitions 查看
顯然 我們的 /dev/vdb1已經劃分成功

[root@localhost Desktop]# cat /proc/partitions
major minor #blocks name

253 0 10485760 vda
253 1 10484142 vda1
253 16 10485760 vdb
253 17 1048576 vdb1
7 0 3655680 loop0
2> 為新建立的分區進行加密
1:
使用命令 cryptsetup luksFormat /dev/vdb1
然後輸入大寫 YES 小寫會沒反應 我估計這裡應該有個bug
然後輸入密碼: 大於 8 位 且不能太簡單

[root@localhost Desktop]# cryptsetup luksFormat /dev/vdb1

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

Are you sure? (Type uppercase yes): YES
Enter passphrase:
Verify passphrase:
2:
接下來進行解密以及使用:
首先使用命令 cryptsetup open /dev/vdb1 haha(這個名字可以隨便取) 進行解密
然後輸入你剛才加密的密碼:
然後對分區進行格式化:mkfs.xfs /dev/mapper/haha
在接著進行 掛載 mount /dev/mapper/haha /mnt 你可以隨意掛載,這是我個人習慣
然後用 df 查看掛載有沒有成功

[root@localhost Desktop]# cryptsetup open /dev/vdb1 haha
Enter passphrase for /dev/vdb1:
[root@localhost Desktop]# mkfs.xfs /dev/mapper/
control haha
[root@localhost Desktop]# mkfs.xfs /dev/mapper/haha
meta-data=/dev/mapper/haha isize=256 agcount=4, agsize=65408 blks
= sectsz=512 attr=2, projid32bit=1
= crc=0
data = bsize=4096 blocks=261632, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=0
log =internal log bsize=4096 blocks=853, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
[root@localhost Desktop]# mount /dev/mapper/haha /mnt
[root@localhost Desktop]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/vda1 10473900 7014964 3458936 67% /
devtmpfs 927072 0 927072 0% /dev
tmpfs 942660 80 942580 1% /dev/shm
tmpfs 942660 17024 925636 2% /run
tmpfs 942660 0 942660 0% /sys/fs/cgroup
/dev/loop0 3654720 3654720 0 100% /var/www/html/pub
/dev/mapper/haha 1043116 32928 1010188 4% /mnt
3:
然我們現在就可以在這個加密的分區中進行操作了,比如說,你建立一些文件
然後將其卸載
然後關閉設備加密 》記得關閉之前必須先卸載》
然後 /mnt中就沒有東西了

[root@localhost mnt]# touch file{1..10}
[root@localhost mnt]# ls
file1 file10 file2 file3 file4 file5 file6 file7 file8 file9
[root@localhost /]# umount /mnt
[root@localhost /]# cryptsetup close /dev/mapper/haha
[root@localhost /]# cd /mnt
[root@localhost mnt]# ls

4:
如果想打開之前那個機密設備可這樣
cryptsetup open /dev/vdb1 heihei 解密
mount /dev/mapper/heihei /mnt 掛載
ls 查看

[root@localhost mnt]# cryptsetup open /dev/vdb1 heihei
Enter passphrase for /dev/vdb1:
[root@localhost mnt]# cd ..
[root@localhost /]# mount /dev/m
mapper/ mcelog mem mqueue/
[root@localhost /]# mount /dev/mapper/heihei /mnt
[root@localhost /]# cd /mnt
[root@localhost mnt]# ls
file1 file10 file2 file3 file4 file5 file6 file7 file8 file9
[root@localhost mnt]#
5:
如果你解密之後,還格式化,那麼之前建立的那些文件也就不再了(格式化你們懂得,就相當於一個全新的一樣)

四:附加內容,開機自動掛載(當然這個必要性不大,這裡僅僅只供參考,還有這種方式)

接下來這些有興趣的可以操作操作,我是實際操作成功的,因為必要性不是很大,所以僅僅提供文字形式。
有linux 基礎的都可以看懂下面的操作,已經夠直白,如有不明白,請留言。。。

vim /etc/crypttab 這個命令用來設定開機解密
如裡面寫: heihei /dev/vdb1 /root/passwd

vim /etc/fstab 開機自動掛載加密設備
/dev/mapper/heihei /mnt xfs defaults 0 0

vim /root/passwd 系統自動讀取密碼記錄文件
這裡面寫解密密碼: 如 2015haha

cryptsetup luksAddKey /dev/vdb1 /root/passwd 把密碼記錄文件和設備關聯
Enter any passphrase: 輸入密碼就可如:2015haha

然後你就可以重起了。

更多RedHat相關信息見RedHat 專題頁面 http://www.linuxidc.com/topicnews.aspx?tid=10

Copyright © Linux教程網 All Rights Reserved