Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Schneier Method (Data Sanitization Method)
#!/bin/bash
# The purpose of this script is to wipe a file system or
# physical disk using the Schneier data sanitation method.
# A.K.A Schneier Method (Data Sanitization Method)
if [ -z "$1" ]
then
echo "No arguments supplied, please pass the path of the disk or "
echo "mount point you want sanitized."
exit 1
fi
read -p "Are you absolutely sure you want to completly wipe $1? [y/N]: " -n 1 -r
echo # (optional) move to a new line
if [[ ! $REPLY =~ ^[Yy]$ ]]
then
[[ "$0" = "$BASH_SOURCE" ]] && exit 1 || return 1 # handle exits from shell or function but don't exit interactive shell
fi
echo "Starting data sanitation"
# Writes 1s directly onto the device - the process will error
#out when the device is full and continue to the next step.
tr '\0' '\377' < /dev/zero > $1
echo "First pass done"
/bin/dd if=/dev/zero of=$1 bs=128M status=progress # Second Pass with 0s
echo "Second pass done"
/bin/dd if=/dev/urandom of=$1 bs=128M status=progress # Third Pass Random
echo "Third pass done"
/bin/dd if=/dev/urandom of=$1 bs=128M status=progress # Fourth Pass Random
echo "Fourth pass done"
/bin/dd if=/dev/urandom of=$1 bs=128M status=progress # Fifth Pass Random
echo "Fifth pass done"
/bin/dd if=/dev/urandom of=$1 bs=128M status=progress # Sixth Pass Random
echo "Sixth pass done"
/bin/dd if=/dev/urandom of=$1 bs=128M status=progress # Seventh Pass Random
echo "$1 has been destroyed."
# Congrats! After a week has passed you have nuked everything!
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment