{"id":6172,"date":"2021-05-02T22:17:03","date_gmt":"2021-05-02T22:17:03","guid":{"rendered":"https:\/\/linuxways.net\/?p=6172"},"modified":"2021-05-02T22:17:03","modified_gmt":"2021-05-02T22:17:03","slug":"how-to-securely-delete-files-using-shred-command-in-debian-10","status":"publish","type":"post","link":"https:\/\/linuxways.net\/de\/debian\/how-to-securely-delete-files-using-shred-command-in-debian-10\/","title":{"rendered":"How to Securely Delete Files Using Shred Command in Debian 10"},"content":{"rendered":"<p>If you have a file containing the sensitive information, deleting it simply with the rm command or pressing the Del key might not be enough. Usually, when you delete a file using the rm command, it removes just from our directory listing. The deleted file remains on the hard disk and can be recovered and misused by an attacker with some necessary skills.<\/p>\n<p>In Linux, the shred command allows you to securely delete the files by overwriting the file repeatedly with gibberish data. This makes retrieval of the original data quite difficult or nearly impossible, even if the deleted file is recovered. Shred command not just overwrites a file but deletes it as well if specified. You can also use it to overwrite partitions or an entire disk.<\/p>\n<p>In this article, we have explained how to use the shred command in Debian10 OS to securely delete the files. The same procedure can be followed in other Debian and Ubuntu versions. We have also discussed some of its command-line options.<\/p>\n<h2>Working with Shred Command<\/h2>\n<p>Shred command is one of the GNU Core Utilities and is available on nearly any Linux system including Debian. Let\u2019s see how to work with the shred command:<\/p>\n<h3>Shred Command Syntax<\/h3>\n<p>Following is the shred command syntax:<\/p>\n<pre>$ shred option &lt;FILE&gt;<\/pre>\n<p>Where the \u201cFILE\u201d can be a file or any hard disk partition.<\/p>\n<p>When you use the shred command without any option, it overwrites the file with gibberish data multiple times. To understand what the shred command does, let\u2019s create a test file named \u201ctestfile.txt\u201d with some text in it.<\/p>\n<pre>$ echo \u201cthis file contains some sample text\u201d &gt; testfile.txt<\/pre>\n<p>This is how our example file looks like:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"436\" height=\"51\" class=\"wp-image-6173\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/04\/word-image-410.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/04\/word-image-410.png 436w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/04\/word-image-410-300x35.png 300w\" sizes=\"auto, (max-width: 436px) 100vw, 436px\" \/><\/p>\n<p>After creating the file, also check the size of the file. We will use it later to compare it against the size of the shredded file.<\/p>\n<pre>$ ls -l testfile.txt<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"649\" height=\"72\" class=\"wp-image-6174\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/04\/word-image-411.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/04\/word-image-411.png 649w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/04\/word-image-411-300x33.png 300w\" sizes=\"auto, (max-width: 649px) 100vw, 649px\" \/><\/p>\n<p>Now run the shred command (without any command line option) followed by the file name that you want to shred.<\/p>\n<pre>$ shred testfile.txt<\/pre>\n<p>The above command will overwrite the <strong>testfile.txt<\/strong> three times (by default). To see what happened to the test file, call the cat command:<\/p>\n<pre>$ cat testfile.txt<\/pre>\n<p>From the cat command output, you will only see the gibberish inside the file.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"855\" height=\"346\" class=\"wp-image-6175\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/04\/word-image-412.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/04\/word-image-412.png 855w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/04\/word-image-412-300x121.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/04\/word-image-412-768x311.png 768w\" sizes=\"auto, (max-width: 855px) 100vw, 855px\" \/><\/p>\n<p>Also, if you view the file size, you will notice it has increased.<\/p>\n<h2><img loading=\"lazy\" decoding=\"async\" width=\"664\" height=\"72\" class=\"wp-image-6176\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/04\/word-image-413.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/04\/word-image-413.png 664w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/04\/word-image-413-300x33.png 300w\" sizes=\"auto, (max-width: 664px) 100vw, 664px\" \/><\/h2>\n<h2>Shred Command Line Options<\/h2>\n<p>The shred command has a few command line options to allow you to expand its functionalities. Let&#8217;s have a look at some examples of how these options work.<\/p>\n<h3>Verbose Output<\/h3>\n<p>Using the -v or &#8211;verbose option, you can view what is happening in the background.<\/p>\n<pre>$ shred -v testfile.txt<\/pre>\n<p>The following output shows the three passes of overwriting the file with the random numbers.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"479\" height=\"94\" class=\"wp-image-6177\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/04\/word-image-414.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/04\/word-image-414.png 479w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/04\/word-image-414-300x59.png 300w\" sizes=\"auto, (max-width: 479px) 100vw, 479px\" \/><\/p>\n<p><strong>Note: Next for all the following examples, we will use the -v option for displaying the output.<\/strong><\/p>\n<h3>Overwrite Multiple Files<\/h3>\n<p>If you have more than one file, you can shred them using a single command instead of shredding them one by one using separate commands. To shred more than one files, type them all as an argument (separated by space) or use the wildcard character to specify all the files which have the same extensions.<\/p>\n<pre>$ shred -v testfile1.txt testfile2.txt testfile3.txt<\/pre>\n<p>All three files will be shredded in a single process as shown in the following screenshot.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"782\" height=\"233\" class=\"wp-image-6178\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/04\/word-image-415.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/04\/word-image-415.png 782w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/04\/word-image-415-300x89.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/04\/word-image-415-768x229.png 768w\" sizes=\"auto, (max-width: 782px) 100vw, 782px\" \/><\/p>\n<h3>Overwrite Drives<\/h3>\n<p>You can also use the shred command to overwrite the drives and partitions. For example, to overwrite all the data on the <strong>\/dev\/sda2<\/strong> partition, the command would be:<\/p>\n<pre>$ sudo shred -v \/dev\/sda2<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"459\" height=\"95\" class=\"wp-image-6179\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/04\/word-image-416.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/04\/word-image-416.png 459w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/04\/word-image-416-300x62.png 300w\" sizes=\"auto, (max-width: 459px) 100vw, 459px\" \/><\/p>\n<h3>Overwrite with zeros<\/h3>\n<p>Usually, the shred command overwrites the file with the random data. However, it will be conspicuous on your system that the shredding operation was performed on this device. You may hide the shredding process using the -z or &#8211;zero option with shred command.<\/p>\n<p>Using shred command with -z or &#8211;zero option first overwrites the file with random numbers, then adds a final overwrite with zeros.<\/p>\n<pre>$ shred -vz testfile.txt<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"458\" height=\"119\" class=\"wp-image-6180\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/04\/word-image-417.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/04\/word-image-417.png 458w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/04\/word-image-417-300x78.png 300w\" sizes=\"auto, (max-width: 458px) 100vw, 458px\" \/><\/p>\n<p>In the above output, you can see that after overwriting the file three times with random numbers, the shred finally overwrote the file with zeros.<\/p>\n<h3>Selectively Overwrite<\/h3>\n<p>The shred command overwrites the files 3 times with random junk. To increase the number of overwrite passes, use the -n or &#8211;iterations option.<\/p>\n<p>For example, to shred the <strong>testfile.txt<\/strong> using 5 number of overwrite passes, the command would be:<\/p>\n<pre>$ shred -vn5 testfile.txt<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"490\" height=\"139\" class=\"wp-image-6181\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/04\/word-image-418.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/04\/word-image-418.png 490w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/04\/word-image-418-300x85.png 300w\" sizes=\"auto, (max-width: 490px) 100vw, 490px\" \/><\/p>\n<h3>Overwrite Only First x Bytes<\/h3>\n<p>The default behavior of the shred command is to overwrite the whole file. Using the -s or &#8211;size option with the shred command allows you to overwrite only first x bytes. For instance, to overwrite only the first 6 bytes of <strong>testfile.txt<\/strong>, the command would be:<\/p>\n<pre>$ shred -vs6 testfile.txt<\/pre>\n<p>The above command will only overwrite the first 6 bytes of the specified file. You can verify it by calling the cat command.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"455\" height=\"143\" class=\"wp-image-6182\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/04\/word-image-419.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/04\/word-image-419.png 455w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/04\/word-image-419-300x94.png 300w\" sizes=\"auto, (max-width: 455px) 100vw, 455px\" \/><\/p>\n<h3>Delete File after Overwriting<\/h3>\n<p>As discussed earlier, the shred command only overwrites the file if we use it without any command line options. However, after overwriting, you can delete the file as well using the -u or &#8211;remove option with the shred command. Note that it will also rename the file before deletion.<\/p>\n<pre>$ shred -vu testfile.txt<\/pre>\n<h3><img loading=\"lazy\" decoding=\"async\" width=\"595\" height=\"421\" class=\"wp-image-6183\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/04\/word-image-420.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/04\/word-image-420.png 595w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/04\/word-image-420-300x212.png 300w\" sizes=\"auto, (max-width: 595px) 100vw, 595px\" \/><\/h3>\n<p>From the above output, you can see that the file was finally removed after being overwritten and renamed.<\/p>\n<h3>View help<\/h3>\n<p>To find more details about the shred command, use the &#8211;help option or visit the man page:<\/p>\n<pre>$ shred --help<\/pre>\n<p>Or<\/p>\n<pre>$ man shred<\/pre>\n<p>In this article, you have learned how to use the shred command in Debian 10 Buster system along with various command line options. You have seen that how the shred command overwrites and deletes the files, making them hard to recover using any recovery tools.<\/p>","protected":false},"excerpt":{"rendered":"<p>If you have a file containing the sensitive information, deleting it simply with the rm command or pressing the Del key might not be enough. Usually, when you&hellip;<\/p>","protected":false},"author":1,"featured_media":6239,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[17,305],"class_list":["post-6172","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-debian","tag-debian-10","tag-shred-command"],"_links":{"self":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/6172","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/comments?post=6172"}],"version-history":[{"count":0,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/6172\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media\/6239"}],"wp:attachment":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media?parent=6172"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/categories?post=6172"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/tags?post=6172"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}