Dateien sicher löschen mit shred
Dateien werden in Linux mit rm gelöscht. Doch der Löschvorgang entfernt nur Inode und Verzeichnis-Eintrag, nicht jedoch die wirklich gespeicherten Daten. Diese bleiben in den Sektoren der Festplatte liegen, bis sie durch eine neue Datei überschrieben werden. Bei vertrautlichen Daten stellt dies ein Problem dar: Mit entsprechenden Tools lassen sich die gelöschten Daten (oder Teile davon) eventuell wieder herstellen.
Um dies zu verbindern gibt es Tools wie shred. Es überschreibt den Inhalt einer Datei mit Zufallsdaten und sorgt so dafür, dass eine Datei unwiederbringlich gelöscht ist. Dazu ruft man shred genauso wie rm auf, wobei es einige interessante Parameter gibt:
- Mit -v wird die ausführliche Ausgabe aktiviert. Eigentlich unnötig, aber interessant, um die Funktion zu sehen. Auch bei sehr großen Dateien ist es eventuell hilfreich, um grob zu wissen, wo das Programm gerade steckt.
- Mit -n legt man die Anzahl der Durchläufe fest, also wie oft die Daten überschrieben werden sollen. Nachdem Forensikexperte Craig Wright 2008 feststellte, dass einmaliges Überschreiben der Daten absolut genügt, sollte wir also -n1 nutzen. Alles andere verwendet nur Zeit und Strom.
- Mit -z gibt man an, dass die Datei nach dem letzten Durchlauf nochmal ausgenullt werden soll. Dies ist zwar nicht nötig, doch monkische Menschen wie ich mögen die Ordnung.
- Mit -u wird die Datei nicht nur überschrieben, sondern am Ende auch gleich gelöscht. Das spart ein nachträgliches aufrufen von rm.
In der Shell sieht das dann wie folgt aus:
# shred -v -n1 -z -u secret shred: secret: pass 1/2 (random)... shred: secret: pass 2/2 (000000)... shred: secret: removed
Freien Speicher löschen
Falls eine Datei aus Versehen schon gelöscht wurde, kann man sie nicht mehr mit shred behandeln. Es hilft dann jedoch, einfach den gesamten freien Platz der Festplatte zu überschreiben. Da man den freien Platz nicht mit einem Namen ansprechen kann, legen wir einfach mit dd eine Datei an, die die ganze Platte füllt:
dd if=/dev/urandom of=/fillup.dat bs=1k
Die Angabe ohne den count-Parameter sorgt dafür, dass dd die Platte so lange mit zufälligen Daten von /dev/urandom beschreibt, bis sie voll ist. Danach kann die Daten mit rm wieder gelöscht werden: rm /fillup.dat
Partition oder ganz Festplatte löschen
Möchte man eine Partition (z.B. /dev/sda3) oder eine ganze Festplatte (z.B. /dev/sda) löschen, kann man einfach deren Gerätenamen in Kombination mit shred einsetzen:
shred -v -n1 -z /dev/...
Hier ist aber unbedingt auf korrekte Angaben zu achten, ist die falsche Partition erstmal überschrieben, gibt es kein Zurück mehr!
Einschränkungen
Moderne Dateisysteme (XFS, ReiserFS, JFS, …) speichern im Journal Daten zwischen, die auf die Festplatte geschrieben werden sollen. Dieses Journal wird von shred nicht gelöscht und kann damit unter umständen noch bereits gelöschte geglaubte Informationen erhalten.
Auch bei EXT3/4 tritt dieses Problem auf, wenn das Dateisystem mit der Option data=journal gemountet wurde. Dies läßt sich einfach durch Eingabe von ‘mount’ prüfen.
Gut, im Journal wird sich in der Praxis nach kurzer Zeit (einigen Schreibvorgängen) nicht mehr viel finden lassen. Wer dennoch auf Nummer Sicher gehen will, dem bleibt nur noch das Auslöschen der ganzen Partition, wie oben beschrieben. Damit werden nämlich nicht nur Dateien, sondern das ganze Filesystem (inkl. Verzeichnis und Journal) gelöscht.
Eine weitere Einschränkung sind die genutzten Festplatten selbst. Diese können nämlich defekte Sektoren für den Computer ausblenden und stattdessen andere, für diesen Zweck reservierte Sektoren, dorthin mappen. Somit ist es möglich, dass sich auch nach komplettem Löschen der Platte noch Informationen darauf befinden, die ein Datenretter wieder herstellen könnte.
Für alte Festplatten gilt daher: Vernichten statt verkaufen. Ein guter Vorschlaghammer genügt dafür übrigens






sehr aufschlussreich
danke!
Wer sich für das Thema interessiert, der sollte sich auch wipe ansehen (wipe – securely erase files from magnetic media). Die Manpage von wipe ist darüberhinaus richtig lesenswert. Hier steht einiges über die Hintergründe des Löschens und wiederherstellen von Daten.
Gruß,
linuxnetzer (http://www.linuxnetz.wordpress.com)
Danke für den Tipp. Ich habe in deinem Kommentar die Verlinkung zur Manpage gleich noch aufgenommen.
Oh, du scheinst da eine andere Version der manpage von wipe zu haben.
Die Version 0.21, die ich meine enthält folgende Beschreibung:
(…)
DESCRIPTION
Recovery of supposedly erased data from magnetic media is easier than
what many people would like to believe. A technique called Magnetic
Force Microscopy (MFM) allows any moderately funded opponent to recover
the last two or three layers of data written to disk; wipe repeatedly
overwrites special patterns to the files to be destroyed, using the
fsync() call and/or the O_SYNC bit to force disk access. In normal
mode, 34 patterns are used (of which 8 are random). These patterns were
recommended in an article from Peter Gutmann (pgut001@cs.auck‐
land.ac.nz) entitled “Secure Deletion of Data from Magnetic and Solid-
State Memory”. A quick mode allows you to use only 4 passes with random
patterns, which is of course much less secure.
NOTE ABOUT JOURNALING FILESYSTEMS AND SOME RECOMMENDATIONS (JUNE 2004)
Journaling filesystems (such as Ext3 or ReiserFS) are now being used by
default by most Linux distributions. No secure deletion program that
does filesystem-level calls can sanitize files on such filesystems,
because sensitive data and metadata can be written to the journal,
which cannot be readily accessed. Per-file secure deletion is better
implemented in the operating system.
Encrypting a whole partition with cryptoloop, for example, does not
help very much either, since there is a single key for all the parti‐
tion.
Therefore wipe is best used to sanitize a harddisk before giving it to
untrusted parties (i.e. sending your laptop for repair, or selling your
disk). Wiping size issues have been hopefully fixed (I apologize for
the long delay).
Be aware that harddisks are quite intelligent beasts those days. They
transparently remap defective blocks. This means that the disk can
keep an albeit corrupted (maybe slightly) but inaccessible and
unerasable copy of some of your data. Modern disks are said to have
about 100% transparent remapping capacity. You can have a look at
recent discussions on Slashdot.
I hereby speculate that harddisks can use the spare remapping area to
secretly make copies of your data. Rising totalitarianism makes this
almost a certitude. It is quite straightforward to implement some sim‐
ple filtering schemes that would copy potentially interesting data.
Better, a harddisk can probably detect that a given file is being
wiped, and silently make a copy of it, while wiping the original as
instructed.
Recovering such data is probably easily done with secret IDE/SCSI com‐
mands. My guess is that there are agreements between harddisk manufac‐
turers and government agencies. Well-funded mafia hackers should then
be able to find those secret commands too.
Don’t trust your harddisk. Encrypt all your data.
Of course this shifts the trust to the computing system, the CPU, and
so on. I guess there are also “traps” in the CPU and, in fact, in
every sufficiently advanced mass-marketed chip. Wealthy nations can
find those. Therefore these are mainly used for criminal investigation
and “control of public dissent”.
People should better think of their computing devices as facilities
lended by the DHS.
IMPORTANT WARNING — READ CAREFULLY
The author, the maintainers or the contributors of this package can NOT
be held responsible in any way if wipe destroys something you didn’t
want it to destroy. Let’s make this very clear. I want you to assume
that this is a nasty program that will wipe out parts of your files
that you didn’t want it to wipe. So whatever happens after you launch
wipe is your entire responsiblity. In particular, no one guarantees
that wipe will conform to the specifications given in this manual page.
Similarly, we cannot guarantee that wipe will actually erase data, or
that wiped data is not recoverable by advanced means. So if nasties
get your secrets because you sold a wiped harddisk to someone you don’t
know, well, too bad for you.
The best way to sanitize a storage medium is to subject it to tempera‐
tures exceeding 1500K. As a cheap alternative, you might use wipe at
your own risk. Be aware that it is very difficult to assess whether
running wipe on a given file will actually wipe it — it depends on an
awful lot of factors, such as : the type of file system the file
resides on (in particular, whether the file system is a journaling one
or not), the type of storage medium used, and the least significant bit
of the phase of the moon.
Wiping over NFS or over a journalling filesystem (ReiserFS etc.) will
most probably not work.
Therefore I strongly recommend to call wipe directly on the correspond‐
ing block device with the appropriate options. However THIS IS AN
EXTREMELY DANGEROUS THING TO DO. Be sure to be sober. Give the right
options. In particular : don’t wipe a whole harddisk (eg. wipe -kD
/dev/hda is bad) since this will destroy your master boot record. Bad
idea. Prefer wiping partitions (eg. wipe -kD /dev/hda2) is good, pro‐
vided, of course, that you have backed up all necessary data.
(…)