Skip to content

Instantly share code, notes, and snippets.

@hctilg
Forked from tavallaie/secure_erase.sh
Created January 2, 2024 16:02
Show Gist options
  • Save hctilg/34c93ab990740bf54c485d9e485cbe0a to your computer and use it in GitHub Desktop.
Save hctilg/34c93ab990740bf54c485d9e485cbe0a to your computer and use it in GitHub Desktop.
**Secure Data Erasure Script (Bash)** This Bash script securely erases data from a specified device with random data, ensuring irrecoverability. Use with caution.
#!/bin/bash
# Check if the script is run with superuser privileges
if [ "$EUID" -ne 0 ]; then
echo "Please run this script as root (sudo)."
exit 1
fi
# Prompt the user for the target devices
read -p "Enter the target devices (e.g., /dev/sdX /dev/sdY): " target_devices
# Iterate through the space-separated list of target devices
for device in $target_devices; do
# Check if the device exists
if [ ! -e "$device" ]; then
echo "Device $device does not exist."
continue
fi
# Overwrite with random data
echo "Erasing $device..."
dd if=/dev/urandom of="$device" bs=4M status=progress
echo "Finished erasing $device."
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment