Red Hat Linux 7 中分區加密技術

來源:互聯網
上載者:User

Red Hat Linux 7 中分區加密技術

一 分區加密簡介
軍工方面重要的保密安全措施技術,國際安全性群組織採取的一種對磁碟內容加密的解決方案,因為殺毒軟體的後覺性是無法保證安全性更高的領域。所以在機密層級較高的領域採取主動性的安全解決方案,而分區加密是其中一種,其密碼編譯演算法是運用當今國際最尖端的採用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

然後你就可以重起了。

本文永久更新連結地址:http://www.bkjia.com/Linux/2016-03/129282tm

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.