原創作品,允許轉載,轉載時請務必以超鏈接形式標明文章 原始出處 、作者信息和本聲明。否則將追究法律責任。http://nolinux.blog.51cto.com/4824967/1436460
使用 fdisk 分區的步驟(略)!
[root@nolinux ~]# dd if=/dev/urandom of=/dev/sda6 # 可選步驟
[root@nolinux ~]# cryptsetup luksFormat /dev/sda6 WARNING! ======== This will overwrite data on /dev/sda6 irrevocably. Are you sure? (Type uppercase yes): YES # 請輸入YES,表示確定 Enter LUKS passphrase: # 輸入你加密的密碼 Verify passphrase: # 再次輸入你加密的密碼
[root@nolinux ~]# cryptsetup luksOpen /dev/sda6 nolinux #回車后會提示你輸入密碼 Enter passphrase for /dev/sda6: [root@nolinux ~]# ll /dev/mapper/nolinux #查看我們生成的映射設備文件 lrwxrwxrwx 1 root root 7 7月 9 21:06 /dev/mapper/nolinux -> ../dm-0
[root@nolinux ~]# mkfs -t ext4 /dev/mapper/nolinux mke2fs 1.41.12 (17-May-2010) 。。。 # 過程省略 This filesystem will be automatically checked every 27 mounts or 180 days, whichever comes first. Use tune2fs -c or -i to override.
[root@nolinux ~]# mkdir /nolinux #創建掛載點 [root@nolinux ~]# mount /dev/mapper/nolinux /nolinux #掛載加密分區
[root@nolinux ~]# echo redhat > /nolinux/test [root@nolinux ~]# cat /nolinux/test redhat
[root@nolinux ~]# cryptsetup luksClose nolinux
[root@nolinux ~]# cryptsetup luksClose nolinux
[root@nolinux ~]# cryptsetup luksOpen /dev/sda6 nolinux #回車后會提示你輸入密碼 Enter passphrase for /dev/sda6: [root@nolinux ~]# ll /dev/mapper/nolinux #查看我們生成的映射設備文件 lrwxrwxrwx 1 root root 7 7月 9 37:06 /dev/mapper/nolinux -> ../dm-0
[root@nolinux ~]# echo 'nolinux /dev/sda6 /root/passwd' >> /etc/crypttab # 映射關系以及密碼文件的路徑 [root@nolinux ~]# cat /etc/crypttab nolinux /dev/sda6 /root/passwd
[root@nolinux ~]# echo redhat > /root/passwd 或 [root@nolinux ~]# dd if=/dev/random of=/root/passwd bs=4096 count=1 記錄了0+1 的讀入 記錄了0+1 的寫出 128字節(128 B)已復制,0.000712986 秒,180 kB/秒
[root@nolinux ~]# cryptsetup luksAddKey /dev/sda6 /root/passwd # 回車后會提示你輸入密碼 Enter any passphrase:
[root@nolinux ~]# echo '/dev/mapper/nolinux /nolinux ext4 defaults,_netdev 0 0' >> /etc/fstab [root@nolinux ~]# tail -1 /etc/fstab /dev/mapper/nolinux /nolinux ext4 defaults,_netdev 0 0
[root@nolinux ~]# mount -a # 由于掛載條目已經寫入/etc/fstab,因此我們可以直接執行mount -a來進行掛載操作 [root@nolinux ~]# df -h|tail -1 /dev/mapper/nolinux 95M 5.6M 85M 7% /nolinux
[root@nolinux ~]# cryptsetup status /dev/mapper/nolinux /dev/mapper/nolinux is active and is in use. type: LUKS1 cipher: aes-cbc-essiv:sha256 keysize: 256 bits device: /dev/sda6 offset: 4096 sectors size: 200704 sectors mode: read/write
轉自:http://nolinux.blog.51cto.com/4824967/1436460
原創文章,作者:s19930811,如若轉載,請注明出處:http://www.www58058.com/1962