完全用 GNU/Linux 工作
30. 銷毀資料 - Shred
過去在 GNU/Linux 裡,凍仁會使用 dd
,此指令會將資料填零而達到抹除磁碟的功用,但就算這樣還是有被專業人士還原的風險;現在凍仁都改用 shred
指令來完成這項任務,此指令是專門用來撕碎資料的。
dd
將 /dev/sdX 裝置填零。
dd if=/dev/zero of=/dev/sdX bs=1M
shred
開始 shred 之前,您必須先安裝 coreutils 套件。
$ sudo aptitude install coreutils
# -v 顯示進度。
# -f 強制寫入,必要時允許變更權限寫入。
# -z 用零覆寫並撕碎。
# -n 指定覆寫次數。
# -n 指定覆寫次數。
抹除硬碟
$ sudo shred -vfz -n 10 /dev/sdX
shred: /dev/sdX:11 次之第 1 次 (random)...
shred: /dev/sdX:11 次之第 1 次 (random)...471MiB/932GiB 0%
shred: /dev/sdX:11 次之第 1 次 (random)...472MiB/932GiB 0%
shred: /dev/sdX:11 次之第 1 次 (random)...949MiB/932GiB 0%
......
抹除檔案
$ shred -vu -n 10 hello-sherd.txt
shred: hello-sherd.txt: pass 1/3 (random)...
shred: hello-sherd.txt: pass 2/3 (random)...
shred: hello-sherd.txt: pass 3/3 (random)...
shred: hello-sherd.txt: removing
shred: hello-sherd.txt: renamed to 000000000000000
shred: 000000000000000: renamed to 00000000000000
shred: 00000000000000: renamed to 0000000000000
shred: 0000000000000: renamed to 000000000000
shred: 000000000000: renamed to 00000000000
shred: 00000000000: renamed to 0000000000
shred: 0000000000: renamed to 000000000
shred: 000000000: renamed to 00000000
shred: 00000000: renamed to 0000000
shred: 0000000: renamed to 000000
shred: 000000: renamed to 00000
shred: 00000: renamed to 0000
shred: 0000: renamed to 000
shred: 000: renamed to 00
shred: 00: renamed to 0
shred: hello-sherd.txt: removed
※ shred 在 ext3, ext4 這類的日誌檔案系統上運作時可能無法完整清除,若真不放心可以試試 hdparm。