4 个用来擦除数据的 Linux 工具
数据 擦除 删除

> 
> 用这些开源工具从你的硬盘驱动器中擦除数据。
> 
> 
> 


![](/data/attachment/album/202110/23/113918sdojp6sj0odgis16.jpg "Tools in a cloud")


保持数据安全的最好方法之一是只向加密的硬盘驱动器写入数据。在一个标准的硬盘上，只要把硬盘挂载就可以查看数据，就像 U 盘一样，甚至可以用 [Scalpel](https://www.redhat.com/sysadmin/find-lost-files-scalpel) 和 [Testdisk](https://www.redhat.com/sysadmin/recover-partition-files-testdisk) 等工具显示和恢复已删除的数据。但是在一个加密的驱动器上，如果没有解密密钥（通常是你在挂载驱动器时输入的密码），数据是无法被读取的。


加密可以在你安装操作系统时建立，有些操作系统甚至可以在安装后的任何时候激活加密功能。


但是，当你卖掉一台电脑或更换一个一开始就没有被加密的驱动器时，你该怎么办呢？


与从一开始就加密你的数据相比，最好的办法是在你用完硬盘后删除数据。


### 负责任的看管者


我经常被要求帮助客户升级一台旧电脑。无一例外，他们更愿意帮助我回收它们，使它们能被别人使用。我很乐意翻新这些旧电脑，用较新的固态驱动器来改装它们，极大地提高性能。


然而，把一个旧驱动器扔进垃圾桶并不是一个好主意。它需要被擦除，然后被妥善处理。我没有把硬盘留在原来的电脑里，而是把它们取出来，放在一个硬盘盒里，然后把它们连接到我的 Linux 电脑上。有几个 Linux 工具可以很容易地完成这个任务。其中一个是 **Gnu Shred**。


### GNU Shred



```
$ sudo shred -vfz /dev/sdX

```

Shred 有许多选项：


* `-n` - 覆盖的次数。默认是三次。
* `-u` - 覆盖并删除。
* `-s` - 要粉碎的字节数。
* `-v` - 显示扩展信息。
* `-f` - 必要时强制改变权限以允许写入。
* `-z` - 最后用 0 覆盖来隐藏粉碎。


使用 `shred --help` 获取更多信息


### ShredOS


ShredOS 是一个<ruby> 即用 <rt>  Live </rt></ruby> Linux 发行版，它的唯一目的是清除驱动器的全部内容。它是在一个名为 DBAN 的类似发行版停止维护后开发的。它使用 `nwipe` 应用，它是 DBAN 的 `dwipe` 的一个分叉。你可以通过下载 32 位或 64 位镜像，并在 Linux 和 macOS 上使用 `dd` 命令将其写入驱动器来制作一个可启动的 USB 驱动器：



```
$ sudo dd if=shredos.img of=/dev/sdX bs=4M status=progress

```

另外，你可以在 Linux、macOS 和 Windows 上使用 [Etcher](https://opensource.com/article/18/7/getting-started-etcherio) 工具烧录。


### dd 命令


清除驱动器的一个常见方法是使用 Linux 的 `dd` 命令。几乎所有的 Linux 安装都安装了 `dd` 工具。确保该驱动器没有被挂载。



```
$ sudo umount /dev/sdXY -l

```

如果你想在整个目标磁盘上写零，执行以下命令。这可能需要一个整个通宵。



```
$ sudo dd if=/dev/urandom of=/dev/sdX bs=10M

```

**警告**：请确保你知道你在系统中的位置，并以正确的驱动器为目标，这样你就不会意外地删除自己的数据。


### Nvme-cli


如果你的计算机包含一个较新的 NVMe 驱动器，你可以安装 [nvme-cli](https://opensource.com/article/21/9/nvme-cli) 程序，并使用 `sanitize` 选项来清除你的驱动器。


`nvme sanitize help` 命令提供了选项列表：


* `--no-dealloc`、`-d` - 净化后不解除分配。
* `--oipbp`、`-i` - 每次覆写后反转模式。
* `--owpass=`、`-n` - 覆写次数。
* `--ause`、`-u` - 允许无限制净化退出。
* `--sanact=`、`-a` - 净化动作。
* `--ovrpat=`、`-p` - 覆写模式。


下面是我使用的命令：



```
$ sudo nvme sanitize /dev/nvme0nX

```

这里的警告与格式化过程相同：首先备份重要的数据，因为这个命令会擦除这些数据！


### 信息管理


你保存在计算机上的信息是很重要的。它属于你，也属于其他任何人。当你卖掉一台电脑或处理一个硬盘时，确保你已经用这些很棒的工具之一清除了你的数据。




---


via: <https://opensource.com/article/21/10/linux-tools-erase-data>


作者：[Don Watkins](https://opensource.com/users/don-watkins) 选题：[lujun9972](https://github.com/lujun9972) 译者：[geekpi](https://github.com/geekpi) 校对：[wxy](https://github.com/wxy)


本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译，[Linux中国](https://linux.cn/) 荣誉推出


OK
One of the best ways to keep your data secure is by only writing data to an encrypted hard drive. On a standard drive, it's possible to view data just by mounting the drive as if it were a thumb drive, and it's even possible to display and recover even deleted data with tools like [Scalpel](https://www.redhat.com/sysadmin/find-lost-files-scalpel) and [Testdisk](https://www.redhat.com/sysadmin/recover-partition-files-testdisk). But on an encrypted drive, data is unreadable without a decryption key (usually a passphrase you enter when mounting the drive.)

Encryption can be established when you install your OS, and some operating systems even make it possible to activate encryption any time after installation.

What do you do when you're selling a computer or replacing a drive that never got encrypted in the first place, though?

The next best thing to encrypting your data from the start is by erasing the data when you're finished with the drive.


## Responsible caretaker

I'm frequently called on to help clients upgrade an old computer. Invariably, they're more than willing to help me recycle them so that they can be used by someone else. I'm happy to refurbish these older computers and refit them with a newer solid-state drive, dramatically improving performance.

However, it's not a good idea to just throw an old drive in the trash. It needs to be erased and then disposed of properly. Rather than leave the drives in the original computer, I remove them, place them in a drive enclosure, and connect them to my Linux computer. Several Linux utilities can easily accomplish this. One of them is the **Gnu Shred** tool.

## GNU Shred

`$ sudo shred -vfz /dev/sdX`


Shred has many options:

- n - the number of overwrites. The default is three.
- u - overwrite and delete.
- s - the number of bytes to shred.
- v - show extended information.
- f - force the change of permissions to allow writing if necessary.
- z - add a final overwrite with zeros to hide shredding.

Use `shred --help`

for more information

## ShredOS

ShredOS is a live Linux distribution with the sole purpose of erasing the entire contents of a drive. It was developed after a similar distribution, called DBAN, was discontinued. It uses the `nwipe`

application, which is a fork of DBAN's `dwipe`

. You can make a bootable USB drive by downloading the 32 bit or 64 bit image and writing it to a drive with the `dd`

command on Linux and macOS:

`$ sudo dd if=shredos.img of=/dev/sdX bs=4M status=progress`


Alternately, you can use the [Etcher](https://opensource.com/article/18/7/getting-started-etcherio) tool on Linux, macOS, and Windows.

## The dd command

A common method for erasing drives is with the Linux `dd`

command. Nearly every Linux installation comes with the `dd`

utility installed. Make sure that the drive is not mounted.

`$ sudo umount /dev/sdXY -l`


If you want to write zeros over your entire target disk, issue the following command. It will probably be an overnight job.

`$ sudo dd if=/dev/urandom of=/dev/sdX bs=10M`


**Warning**: Be sure that you know where you are on your system and target the correct drive so that you don't accidentally erase your own data.

## Nvme-cli

If your computer contains one of the newer NVMe drives, you can install the [nvme-cli](https://opensource.com/article/21/9/nvme-cli) utilities and use the `sanitize`

option to erase your drive.

The command `nvme sanitize help`

command provides you with a list of sanitize options, which include the following:

- --no-dealloc, -d - No deallocate after sanitize.
- --oipbp, -i - Overwrite invert pattern between passes.
- --owpass=, -n - Overwrite pass count.
- --ause, -u - Allow unrestricted sanitize exit.
- --sanact=, -a - Sanitize action.
- --ovrpat=, -p - Overwrite pattern.

Here is the command I use:

`$ sudo nvme sanitize /dev/nvme0nX`


The same warnings apply here as with the format process: back up important data first because this command erases it!

## Information management

The information you keep on your computer is important. It belongs to you and to know one else. When you're selling off a computer or disposing of a hard drive, make sure you've cleared it of your data with one of these great tools.

## 1 Comment