Skip to content

Instantly share code, notes, and snippets.

@jgavinray
Last active September 15, 2019 18:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jgavinray/e7d346748fc5a1bda8f99a92711a1164 to your computer and use it in GitHub Desktop.
Save jgavinray/e7d346748fc5a1bda8f99a92711a1164 to your computer and use it in GitHub Desktop.
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