{"id":82736,"date":"2023-11-23T02:32:03","date_gmt":"2023-11-22T18:32:03","guid":{"rendered":"http:\/\/lrxjmw.cn\/?p=82736"},"modified":"2023-11-23T02:32:03","modified_gmt":"2023-11-22T18:32:03","slug":"linux-disk-encryption","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/linux-disk-encryption.html","title":{"rendered":"Linux \u4e2d\u5982\u4f55\u78c1\u76d8\u52a0\u5bc6"},"content":{"rendered":"
[root@vipuser200 ~]# yum -y install cryptsetup#yum\u5b89\u88c5\u52a0\u5bc6\u5de5\u5177<\/pre>\n2\u3001\u5176\u6b21\u6211\u4eec\u5728\u865a\u62df\u673a\u4e0a\u6dfb\u52a0\u4e00\u4e2a\u5206\u533a<\/strong><\/span><\/div>\n[root@vipuser200 ~]# fdisk \/dev\/sdd#\u6b65\u9aa4\u5c31\u4e0d\u8be6\u89e3\u4e86\r\n\r\n[root@vipuser200 ~]# partprobe \/dev\/sdd#\u83b7\u53d6\u5206\u533a\u8868\r\n\r\n[root@vipuser200 ~]# cryptsetup luksFormat \/dev\/sdd1#\u8bbe\u7f6e\u5bc6\u7801Format F\u5fc5\u987b\u5927\u5199\r\n\r\nWARNING!\r\n\r\n========\r\n\r\nThis will overwrite data on \/dev\/sdd1 irrevocably.\r\n\r\nAre you sure? (Type uppercase yes): YES#\u5fc5\u987b\u4e3a\u5927\u5199YES\r\n\r\nEnter LUKS passphrase: #\u5bc6\u7801\r\n\r\nVerify passphrase:#\u518d\u6b21\u9a8c\u8bc1\u5bc6\u7801\r\n<\/pre>\n3\u3001\u6620\u5c04\u5206\u533a\u8fd9\u6837\u505a\u4e8b\u4e3a\u4e86\u5b89\u5168\u7c7b\u4f3c\u4e8e\u6628\u5929\u7684\u8f6f\u8fde\u63a5<\/strong><\/span><\/div>\n[root@vipuser200 ~]# cryptsetup luksOpen \/dev\/sdd1 my_disk#Open O\u5fc5\u987b\u5927\u5199\r\n\r\nEnter passphrase for \/dev\/sdd1:#\u5bc6\u7801\r\n<\/pre>\n4\u3001\u67e5\u770b\u52a0\u5bc6\u78c1\u76d8\u6620\u5c04\u5206\u533a<\/strong><\/span><\/div>\n[root@vipuser200 ~]# ll \/dev\/mapper\/#\u5b58\u653e\u4f4d\u7f6e\r\n\r\ntotal 0\r\n\r\ncrw-rw---- 1 root root 10, 58 Jul 27 01:01 control\r\n\r\nlrwxrwxrwx 1 root root 7 Jul 27 01:20 my_disk -> ..\/dm-0\r\n\r\n#\u6ce8\uff1amy_disk \u6307\u5411\/dm-0\r\n<\/pre>\n5\u3001\u683c\u5f0f\u5316\u6620\u5c04\u5206\u533a<\/strong><\/span><\/div>\n[root@vipuser200 ~]# mkfs.ext4 \/dev\/mapper\/my_disk\r\n<\/pre>\n6\u3001\u521b\u5efa\u6302\u8f7d\u70b9\u5e76\u6302\u5728\u5206\u533a<\/strong><\/span><\/div>\n[root@vipuser200 ~]# mkdir mapper_mount#\u521b\u5efa\u6302\u8f7d\u70b9\r\n\r\n[root@vipuser200 ~]# mount \/dev\/mapper\/my_disk mapper_mount\/#\u6302\u8f7d\r\n<\/pre>\n7\u3001\u67e5\u770b\u6302\u8f7d\u72b6\u51b5<\/strong><\/span><\/div>\n[root@vipuser200 ~]# df -h\r\n\r\nFilesystem Size Used Avail Use% Mounted on\r\n\r\n\/dev\/sda2 9.9G 1.4G 8.0G 15% \/\r\n\r\ntmpfs 479M 0 479M 0% \/dev\/shm\r\n\r\n\/dev\/sda1 194M 27M 158M 15% \/boot\r\n\r\n\/dev\/sr0 3.6G 3.6G 0 100% \/mnt\r\n\r\n\/dev\/mapper\/my_disk 20G 172M 19G 1% \/root\/mapper_mount\r\n<\/pre>\n8\u3001\u5173\u95ed\u52a0\u5bc6\u5206\u533a<\/strong><\/span><\/div>\n[root@vipuser200 ~]# umount \/root\/mapper_mount\/#\u9996\u5148\u5378\u8f7d\r\n\r\n[root@vipuser200 ~]# cryptsetup luksClose \/dev\/mapper\/my_disk\r\n\r\n#\u5173\u95ed\u52a0\u5bc6\u5206\u533a luksClose C\u5927\u5199\r\n\r\n[root@vipuser200 ~]# mount \/dev\/sdd1 mapper_mount\/#\u518d\u6b21\u6302\u8f7d\u53d1\u73b0\u5931\u8d25\r\n\r\nmount: unknown filesystem type 'crypto_LUKS\r\n\r\n#\u5982\u679c\u9700\u8981\u4f7f\u7528\u8be5\u78c1\u76d8\u5219\u9700\u8981\u5148\u6253\u5f00\u78c1\u76d8\u53caluksOpen\u547d\u4ee4\u7136\u540e\u8f7d\u6302\u8f7d\r\n<\/pre>\n\n\u539f\u6587\u6765\u81ea\uff1ahttp:\/\/www.toutiao.com\/a6334667338880647426\/?tt_from=mobile_qq&utm_campaign=client_share&app=news_article&utm_source=mobile_qq&iid=5528560677&utm_medium=toutiao_android<\/a><\/p>\n