{"id":12893,"date":"2019-03-29T01:25:55","date_gmt":"2019-03-29T01:25:55","guid":{"rendered":"http:\/\/www.appservgrid.com\/paw92\/?p=12893"},"modified":"2019-03-29T01:25:55","modified_gmt":"2019-03-29T01:25:55","slug":"how-to-block-usb-storage-devices-in-linux-servers","status":"publish","type":"post","link":"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/03\/29\/how-to-block-usb-storage-devices-in-linux-servers\/","title":{"rendered":"How to Block USB Storage Devices in Linux Servers"},"content":{"rendered":"<p>In order to protect sensitive data extraction from servers by users who have physical access to machines, it\u2019s a best practice to disable all USB storage support in Linux kernel.<\/p>\n<p>In order to disable USB storage support, we first need to identify if the storage driver is loaded into Linux kernel and the name of the driver (<strong>module<\/strong>) responsible with storage driver.<\/p>\n<p>Run the\u00a0<strong>lsmod command<\/strong>\u00a0to list all loaded kernel drivers and filter the output via\u00a0<a href=\"https:\/\/www.tecmint.com\/12-practical-examples-of-linux-grep-command\/\" target=\"_blank\" rel=\"noopener\">grep command<\/a>\u00a0with the search string \u201c<strong>usb_storage<\/strong>\u201d.<\/p>\n<pre># lsmod | grep usb_storage\r\n<\/pre>\n<div id=\"attachment_28391\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/01\/List-USB-Storage-Drivers.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-28391\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/01\/List-USB-Storage-Drivers.png\" alt=\"List USB Storage Drivers\" width=\"353\" height=\"62\" aria-describedby=\"caption-attachment-28391\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-28391\" class=\"wp-caption-text\">List USB Storage Drivers<\/p>\n<\/div>\n<p>From\u00a0<strong>lsmod<\/strong>\u00a0command, we can see that the\u00a0<strong>sub_storage<\/strong>\u00a0module is in use by\u00a0<strong>UAS<\/strong>\u00a0module. Next, unload both USB storage modules from kernel and verify if the removal has been successfully completed, by issuing the below commands.<\/p>\n<pre># modprobe -r usb_storage\r\n# modprobe -r uas\r\n# lsmod | grep usb<\/pre>\n<p>Next, list the content of the current runtime kernel usb storage modules directory by issuing the below command and identify the\u00a0<strong>usb-storage<\/strong>\u00a0driver name. Usually this module should be named\u00a0<strong>usb-storage.ko.xz<\/strong>\u00a0or\u00a0<strong>usb-storage.ko<\/strong>.<\/p>\n<pre># ls \/lib\/modules\/`uname -r`\/kernel\/drivers\/usb\/storage\/\r\n<\/pre>\n<p>In order to block USB storage module form loading into kernel, change directory to kernel usb storage modules path and rename the\u00a0<strong>usb-storage.ko.xz<\/strong>\u00a0module to\u00a0<strong>usb-storage.ko.xz.blacklist<\/strong>, by issuing the below commands.<\/p>\n<pre># cd \/lib\/modules\/`uname -r`\/kernel\/drivers\/usb\/storage\/\r\n# ls\r\n# mv usb-storage.ko.xz usb-storage.ko.xz.blacklist\r\n<\/pre>\n<div id=\"attachment_28392\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/01\/Block-USB-Storage-in-Linux.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-28392\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/01\/Block-USB-Storage-in-Linux.png\" sizes=\"auto, (max-width: 800px) 100vw, 800px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/01\/Block-USB-Storage-in-Linux.png 800w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/01\/Block-USB-Storage-in-Linux-768x203.png 768w\" alt=\"Block USB Storage in Linux\" width=\"800\" height=\"211\" aria-describedby=\"caption-attachment-28392\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-28392\" class=\"wp-caption-text\">Block USB Storage in Linux<\/p>\n<\/div>\n<p>In\u00a0<strong>Debian<\/strong>\u00a0based Linux distributions, issue the below commands to block\u00a0<strong>usb-storage<\/strong>\u00a0module from loading into Linux kernel.<\/p>\n<pre># cd \/lib\/modules\/`uname -r`\/kernel\/drivers\/usb\/storage\/ \r\n# ls\r\n# mv usb-storage.ko usb-storage.ko.blacklist\r\n<\/pre>\n<div id=\"attachment_28393\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/01\/Block-USB-in-Debian-Ubuntu.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-28393\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/01\/Block-USB-in-Debian-Ubuntu.png\" sizes=\"auto, (max-width: 800px) 100vw, 800px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/01\/Block-USB-in-Debian-Ubuntu.png 800w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/01\/Block-USB-in-Debian-Ubuntu-768x267.png 768w\" alt=\"Block USB in Debian and Ubuntu\" width=\"800\" height=\"278\" aria-describedby=\"caption-attachment-28393\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-28393\" class=\"wp-caption-text\">Block USB in Debian and Ubuntu<\/p>\n<\/div>\n<p>Now, whenever you plug-in a USB storage device, the kernel will be fail to load the storage device driver intro kernel. To revert changes, just rename the usb module blacklisted back to its old name.<\/p>\n<pre># cd \/lib\/modules\/`uname -r`\/kernel\/drivers\/usb\/storage\/\r\n# mv usb-storage.ko.xz.blacklist usb-storage.ko.xz\r\n<\/pre>\n<p>However, this method applies only to runtime kernel modules. In case you want to blacklist USB storage modules form all available kernels in the system, enter each kernel module directory version path and rename the\u00a0<strong>usb-storage.ko.xz<\/strong>\u00a0to\u00a0<strong>usb-storage.ko.xz.blacklist<\/strong>.<\/p>\n<p><a href=\"https:\/\/www.tecmint.com\/block-usb-storage-devices-in-linux\/\" target=\"_blank\" rel=\"noopener\">Source<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In order to protect sensitive data extraction from servers by users who have physical access to machines, it\u2019s a best practice to disable all USB storage support in Linux kernel. In order to disable USB storage support, we first need to identify if the storage driver is loaded into Linux kernel and the name of &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/03\/29\/how-to-block-usb-storage-devices-in-linux-servers\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;How to Block USB Storage Devices in Linux Servers&#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-12893","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\/12893","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=12893"}],"version-history":[{"count":1,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/12893\/revisions"}],"predecessor-version":[{"id":12894,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/12893\/revisions\/12894"}],"wp:attachment":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/media?parent=12893"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/categories?post=12893"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/tags?post=12893"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}