Confirm the target hard disk device name (such as /dev/sda) to avoid accidentally deleting the system disk; 2. Use sudo dd if=/dev/zero of=/dev/sdX bs=1M status=progress to overwrite the zero value in full disk, which is suitable for most scenarios; 3. Use sudo shred -v -n 3 /dev/sdX for three random data overwrites to ensure that it cannot be restored; 4. Optionally execute sudo badblocks -wsv /dev/sdX for destructive write tests; finally use sudo hexdump -C /dev/sdX | head to verify that it is all zero and complete safe erasing.
If you're decommissioning a hard drive, selling an old laptop, or just want to make sure your data is truly gone, simply deleting files or reformatting isn't enough. On Linux, there are reliable, built-in tools to securely erase a hard drive so data can't be recovered—even with forensic tools.

Here's how to do it right:
? 1. Identify the Correct Drive
Before doing anything, double-check which drive you're targeting— wiping the wrong one could destroy your OS or data .

lsblk
or
sudo fdisk -l
Look for the device name like /dev/sda
, /dev/nvme0n1
, etc.
? Pro tip: Unplug all unnecessary drives to avoid mistakes.

?? 2. Use dd
with /dev/zero
(Basic Secure Wipe)
This overwrites the entire drive with zeros—good for most cases:
sudo dd if=/dev/zero of=/dev/sdX bs=1M status=progress
Replace sdX
with your actual drive (eg, sda
).
-
if=/dev/zero
= input is all zeros -
of=/dev/sdX
= output to your target drive -
bs=1M
= faster write speed -
status=progress
= shows real-time progress
? Why this works : Overwriting with zeros makes most recovery tools useless.
?? Note : This takes time—hours for large drives.
? 3. For Extra Security: Use shred
shred
writes random data multiple times (default: 3 passes), making recovery nearly impossible:
sudo shred -v -n 3 /dev/sdX
-
-v
= verbose (shows progress) -
-n 3
= 3 overwrite passes (you can use more, but 3 is usually sufficient)
? Use this if the drive hold sensitive data like passwords, financial records, or personal documents.
? 4. Optional: Use badblocks
for Destructive Write Test
This is overkill for most users but useful if you want to both test for bad sectors and wipe:
sudo badblocks -wsv /dev/sdX
-
-w
= destructive write test (wipes the drive) -
-s
= show progress -
-v
= verbose
This does one pass of predefined patterns —not as through as shred
, but faster and still secure for casual use.
? Final Step: Verify the Wipe
After wiping, check that the drive is actually blank:
sudo hexdump -C /dev/sdX | head
You should see only zeros (like 00000000: 00 00 00 ...
). If you see readable text or patterns, the wipe failed.
?? Important Notes:
- Unmount all partitions first :
sudo umount /dev/sdX*
- SSDs vs HDDs : For SSDs, use
blkdiscard
or the drive's built-in secure erase (viahdparm
)—because wear leveling can leave data in unused blocks. - Physical destruction is the only 100% secure method for top-secret data—but that's beyond software.
- Identify the drive ?
- Run
shred -v -n 3 /dev/sdX
? - Verify with
hexdump
?
Basically, for 99% of users:
It's not glamorous—but it's secure, simple, and uses tools already on your Linux system.
The above is the detailed content of How to Securely Erase a Hard Drive on Linux. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Linux system restricts user resources through the ulimit command to prevent excessive use of resources. 1.ulimit is a built-in shell command that can limit the number of file descriptors (-n), memory size (-v), thread count (-u), etc., which are divided into soft limit (current effective value) and hard limit (maximum upper limit). 2. Use the ulimit command directly for temporary modification, such as ulimit-n2048, but it is only valid for the current session. 3. For permanent effect, you need to modify /etc/security/limits.conf and PAM configuration files, and add sessionrequiredpam_limits.so. 4. The systemd service needs to set Lim in the unit file

Informix and MySQL are both popular relational database management systems. They perform well in Linux environments and are widely used. The following is a comparison and analysis of the two on the Linux platform: Installing and configuring Informix: Deploying Informix on Linux requires downloading the corresponding installation files, and then completing the installation and configuration process according to the official documentation. MySQL: The installation process of MySQL is relatively simple, and can be easily installed through system package management tools (such as apt or yum), and there are a large number of tutorials and community support on the network for reference. Performance Informix: Informix has excellent performance and

To tune MySQL into a Chinese interface, it can be implemented through MySQLWorkbench or command line tools. 1) In MySQLWorkbench, open "Preferences", select the "Appearance" tab, and then select "Chinese(Simplified)" in the "Language" drop-down menu, and restart. 2) When using command line tools, set the operating system locale variables, such as using "exportLANG=zh_CN.UTF-8" on Linux or macOS, and then run the mysql client.

Debian Text Editor is a basic text editing tool, mainly used for daily simple text editing work. Compared with other mainstream editors, it has certain limitations in performance and user experience. Here are the advantages and features of several other editors compared to Debian text editors: Notepad Loading large files speed: Notepad can quickly load large files, such as 1GB-sized SQL files in just 8 seconds, which is nearly 47 times faster than standard text editors. Code coloring function: Supports code coloring in about 80 programming languages, which helps improve coding efficiency. Batch operation capability: It has column editing mode, which is convenient for performing batch processing tasks such as financial verification or operation and maintenance logs. Extension plug-in branch

Starting SFTP service in Debian systems usually requires the help of an OpenSSH server. The following are the specific steps: 1. Install the OpenSSH server First, confirm that the OpenSSH server is installed on your Debian system. If not installed, you can complete the installation by following command: sudoaptupdatesudoaptininstallopenssh-server2. After starting the OpenSSH server installation is completed, the OpenSSH server will generally start automatically. You can check its running status through the following command: sudosystemctlstatusssh If the service is not running, you can start it with the following command: s

Linux and Windows have their own advantages and disadvantages in CPU and memory usage: 1) Linux uses time slice-based scheduling algorithms to ensure fairness and efficiency; Windows uses priority scheduling, which may cause low-priority processes to wait. 2) Linux manages memory through paging and switching mechanisms to reduce fragmentation; Windows tends to pre-allocate and dynamic adjustment, and efficiency may fluctuate.

Linux's cost of ownership is usually lower than Windows. 1) Linux does not require license fees, saving a lot of costs, while Windows requires purchasing a license. 2) Linux has low hardware requirements and can extend the service life of the device. 3) The Linux community provides free support to reduce maintenance costs. 4) Linux is highly secure and reduces productivity losses. 5) The Linux learning curve is steep, but Windows is easier to use. The choice should be based on specific needs and budget.

LinuxoftenoutperformsWindowsinI/Operformanceduetoitscustomizablekernelandfilesystems,whileWindowsoffersmoreuniformperformanceacrosshardware.1)LinuxexcelswithcustomizableI/OschedulerslikeCFQandDeadline,enhancingperformanceinhigh-throughputapplications
