{"id":12149,"date":"2019-03-22T12:29:56","date_gmt":"2019-03-22T12:29:56","guid":{"rendered":"http:\/\/www.appservgrid.com\/paw92\/?p=12149"},"modified":"2019-03-22T12:29:56","modified_gmt":"2019-03-22T12:29:56","slug":"3-ways-to-permanently-and-securely-delete-files-and-directories-in-linux","status":"publish","type":"post","link":"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/03\/22\/3-ways-to-permanently-and-securely-delete-files-and-directories-in-linux\/","title":{"rendered":"3 Ways to Permanently and Securely Delete \u2018Files and Directories\u2019 in Linux"},"content":{"rendered":"<p>In most cases the means we use to\u00a0<a href=\"https:\/\/www.tecmint.com\/delete-all-files-in-directory-except-one-few-file-extensions\/\" target=\"_blank\" rel=\"noopener\">delete a file from our computers<\/a>\u00a0such as using\u00a0<code>Delete<\/code>\u00a0key, Trash files or\u00a0<code>rm<\/code>\u00a0command, which do not permanently and securely remove the file from the hard disk (or any storage media).<\/p>\n<p>The file is simply hidden from users and it resides somewhere on the hard disk. It can be recovered by data thieves, law enforcement or other threats.<\/p>\n<p><b>Suggested Read:<\/b>\u00a0<a href=\"https:\/\/www.tecmint.com\/delete-all-files-in-directory-except-one-few-file-extensions\/\" target=\"_blank\" rel=\"noopener\">3 Ways to Delete All Files in a Directory Except One or Few Files<\/a><\/p>\n<p>Assuming a file contains classified or secret content such as\u00a0<strong>usernames<\/strong>\u00a0and\u00a0<strong>passwords<\/strong>\u00a0of a security system, an attacker with the necessary knowledge and skills can easily\u00a0<a href=\"https:\/\/www.tecmint.com\/photorec-recover-deleted-lost-files-in-linux\/\" target=\"_blank\" rel=\"noopener\">recover a deleted copy of the file<\/a>\u00a0and access these user credentials (and you can probably guess the aftermath of such as scenario).<\/p>\n<p>In this article, we will explain a number of command line tools for permanently and securely deleting files in Linux.<\/p>\n<h3>1. Shred \u2013 Overwrite a File to Hide Content<\/h3>\n<p><strong>shred<\/strong>\u00a0overwrites a file to hide its contents, and can optionally delete it as well.<\/p>\n<pre>$ shred -zvu -n  5 passwords.list\r\n<\/pre>\n<p>In the command below, the options:<\/p>\n<ol>\n<li><code>-z<\/code>\u00a0\u2013 adds a final overwrite with zeros to hide shredding<\/li>\n<li><code>-v<\/code>\u00a0\u2013 enables display of operation progress<\/li>\n<li><code>-u<\/code>\u00a0\u2013 truncates and removes file after overwriting<\/li>\n<li><code>-n<\/code>\u00a0\u2013 specifies number of times to overwrite file content (the default is 3)<\/li>\n<\/ol>\n<div id=\"attachment_24143\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/01\/shred-command-example.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-24143\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/01\/shred-command-example.png\" alt=\"shred - overwrite a file to hide its contents\" width=\"593\" height=\"458\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">shred \u2013 overwrite a file to hide its contents<\/p>\n<\/div>\n<p>You can find more usage options and information in the shred man page:<\/p>\n<pre>$ man shred\r\n<\/pre>\n<h3>2. Wipe \u2013 Securely Erase Files in Linux<\/h3>\n<p>A Linux\u00a0<strong>wipe<\/strong>\u00a0command securely erases files from magnetic memory and thereby making it impossible to\u00a0<a href=\"https:\/\/www.tecmint.com\/recover-deleted-file-in-linux\/\" target=\"_blank\" rel=\"noopener\">recover deleted files or directory content<\/a>.<\/p>\n<p>First, you need to install wipe tool in order to it, run the appropriate command below:<\/p>\n<pre>$ sudo apt-get install wipe   [On Debian and its derivatives]\r\n$ sudo yum install wipe       [On RedHat based systems]\r\n<\/pre>\n<p>The following command will destroy everything under the directory\u00a0<strong>private<\/strong>.<\/p>\n<pre>$ wipe -rfi private\/*\r\n<\/pre>\n<p>where the flags used:<\/p>\n<ol>\n<li><code>-r<\/code>\u00a0\u2013 tells wipe to recurse into subdirectories<\/li>\n<li><code>-f<\/code>\u00a0\u2013 enables forced deletion and disable confirmation query<\/li>\n<li><code>-i<\/code>\u00a0\u2013 shows progress of deletion process<\/li>\n<\/ol>\n<div id=\"attachment_24144\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/01\/Wipe-Securely-Erase-Files.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-24144\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/01\/Wipe-Securely-Erase-Files.png\" sizes=\"auto, (max-width: 963px) 100vw, 963px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/01\/Wipe-Securely-Erase-Files.png 963w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/01\/Wipe-Securely-Erase-Files-768x199.png 768w\" alt=\"Wipe - Securely Erase Files in Linux\" width=\"963\" height=\"249\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">Wipe \u2013 Securely Erase Files in Linux<\/p>\n<\/div>\n<p><strong>Note<\/strong>: Wipe only works reliably on magnetic memory, therefore use the other methods for solid state disks (memory).<\/p>\n<p>Read through the\u00a0<strong>wipe<\/strong>\u00a0man page for additional usage options and instructions:<\/p>\n<pre>$ man wipe\r\n<\/pre>\n<h3>3. Secure-deletetion Toolkit for Linux<\/h3>\n<p><strong>Secure-delete<\/strong>\u00a0is a collection of secure file deletion tools, that contains\u00a0<strong>srm<\/strong>\u00a0(secure_deletion) tool, which is used to remove files securely.<\/p>\n<p>First you need to install it using the relevant command below:<\/p>\n<pre>$ sudo apt-get install secure-delete   [On Debian and its derivatives]\r\n$ sudo yum install secure-delete       [On RedHat based systems]\r\n<\/pre>\n<p>Once installed, you can use\u00a0<strong>srm<\/strong>\u00a0tool to remove files or directories securely on a Linux system as follows.<\/p>\n<pre>$ srm -vz private\/*\r\n<\/pre>\n<p>where the options used:<\/p>\n<ol>\n<li><code>-v<\/code>\u00a0\u2013 enables verbose mode<\/li>\n<li><code>-z<\/code>\u00a0\u2013 wipes the last write with zeros instead of random data<\/li>\n<\/ol>\n<div id=\"attachment_24145\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/01\/srm-securely-delete-Files-in-Linux.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-24145\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/01\/srm-securely-delete-Files-in-Linux.png\" alt=\"srm - Securely Delete Files in Linux \" width=\"725\" height=\"154\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">srm \u2013 Securely Delete Files in Linux<\/p>\n<\/div>\n<p>Read through the\u00a0<strong>srm<\/strong>\u00a0man page for more usage options and information:<\/p>\n<pre>$ man srm\r\n<\/pre>\n<h3>4. sfill -Secure Free Disk\/Inode Space Wiper<\/h3>\n<p><strong>sfill<\/strong>\u00a0is a part of\u00a0<strong>secure-deletetion<\/strong>\u00a0toolkit, is a secure free disk and inode space wiper, it deletes files on free disk space in a secure method. sfill\u00a0<a href=\"https:\/\/www.tecmint.com\/find-top-large-directories-and-files-sizes-in-linux\/\" target=\"_blank\" rel=\"noopener\">checks the the free space on the specified partition<\/a>\u00a0and fills it with random data from \/<strong>dev\/urandom<\/strong>.<\/p>\n<p>The command below will execute\u00a0<strong>sfill<\/strong>\u00a0on my root partition, with the\u00a0<code>-v<\/code>\u00a0switch enabling verbose mode:<\/p>\n<pre>$ sudo sfill -v \/home\/aaronkilik\/tmp\/\r\n<\/pre>\n<p>Assuming you created a separate partition,\u00a0<code>\/home<\/code>\u00a0to store normal system users home directories, you can specify a directory on that partition to apply\u00a0<strong>sfill<\/strong>\u00a0on it:<\/p>\n<pre>$ sudo sfill -v \/home\/username\r\n<\/pre>\n<p>The are a few limitations of\u00a0<strong>sfill<\/strong>\u00a0that you can read about in the man page, where you can also find additional usage flags and instructions:<\/p>\n<pre>$ man sfill\r\n<\/pre>\n<p><strong>Note<\/strong>: These following two tools (<strong>sswap<\/strong>\u00a0and\u00a0<strong>sdmem<\/strong>) in the\u00a0<strong>secure-deletetion<\/strong>\u00a0toolkit are not directly relevant for the scope of this guide, however, we will explain them for knowledge purpose and future use.<\/p>\n<h3>5. sswap \u2013 Secure Swap Wiper<\/h3>\n<p>It is a secure partition wiper,\u00a0<strong>sswap<\/strong>\u00a0deletes data present on your swap partition in a secure manner.<\/p>\n<p><strong>Caution<\/strong>: remember to unmount your\u00a0<strong>swap<\/strong>\u00a0partition before using\u00a0<strong>sswap<\/strong>! Otherwise your system might crash!<\/p>\n<p>Simply determine you swap partition (and check if paging and swapping devices\/files are turned on using\u00a0<strong>swapon<\/strong>\u00a0command), next, disable paging and swapping devices\/files with\u00a0<strong>swapoff<\/strong>\u00a0command (renders swap partition unusable).<\/p>\n<p>Then run\u00a0<strong>sswap<\/strong>\u00a0command on the swap partition:<\/p>\n<pre>$ cat \/proc\/swaps \r\n$ swapon\r\n$ sudo swapoff \/dev\/sda6\r\n$ sudo sswap \/dev\/sda6    #this command may take some time to complete with 38 default passes\r\n<\/pre>\n<div id=\"attachment_24146\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/01\/sswap-Secure-Swap-Wiper.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-24146\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/01\/sswap-Secure-Swap-Wiper.png\" sizes=\"auto, (max-width: 805px) 100vw, 805px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/01\/sswap-Secure-Swap-Wiper.png 805w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/01\/sswap-Secure-Swap-Wiper-768x256.png 768w\" alt=\"sswap - Secure Swap Wiper\" width=\"805\" height=\"268\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">sswap \u2013 Secure Swap Wiper<\/p>\n<\/div>\n<p>Make an effort to read through the\u00a0<strong>sswap<\/strong>\u00a0man page for more usage options and information:<\/p>\n<pre>$ man sswap\r\n<\/pre>\n<h3>6. sdmem \u2013 Secure Memory Wiper<\/h3>\n<p><strong>sdmem<\/strong>\u00a0is a secure memory wiper, it is designed to remove data present in your memory (RAM) in a secure manner.<\/p>\n<p>It was originally named\u00a0<a href=\"https:\/\/www.tecmint.com\/smem-linux-memory-usage-per-process-per-user\/\" target=\"_blank\" rel=\"noopener\">smem<\/a>, but because on\u00a0<strong>Debain<\/strong>\u00a0systems there exists another package called\u00a0<a href=\"https:\/\/www.tecmint.com\/smem-linux-memory-usage-per-process-per-user\/\" target=\"_blank\" rel=\"noopener\">smem \u2013 report memory consumption on per-process and per-user basis<\/a>, the developer decided to rename it\u00a0<strong>sdmem<\/strong>.<\/p>\n<pre>$ sudo sdmem -f -v\r\n<\/pre>\n<p>For more usage information, read through the sdmem man page:<\/p>\n<pre>$ man sdmem \r\n<\/pre>\n<p><b>Suggested Read:<\/b>\u00a0<a href=\"https:\/\/www.tecmint.com\/photorec-recover-deleted-lost-files-in-linux\/\" target=\"_blank\" rel=\"noopener\">PhotoRec \u2013 Recover Deleted or Lost Files in Linux<\/a><\/p>\n<p>That\u2019s it! In this article, we reviewed a number command line tools for permanently as well as securely deleting files in Linux.<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In most cases the means we use to\u00a0delete a file from our computers\u00a0such as using\u00a0Delete\u00a0key, Trash files or\u00a0rm\u00a0command, which do not permanently and securely remove the file from the hard disk (or any storage media). The file is simply hidden from users and it resides somewhere on the hard disk. It can be recovered by &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/03\/22\/3-ways-to-permanently-and-securely-delete-files-and-directories-in-linux\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;3 Ways to Permanently and Securely Delete \u2018Files and Directories\u2019 in Linux&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-12149","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/12149","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/comments?post=12149"}],"version-history":[{"count":1,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/12149\/revisions"}],"predecessor-version":[{"id":12150,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/12149\/revisions\/12150"}],"wp:attachment":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/media?parent=12149"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/categories?post=12149"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/tags?post=12149"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}