linux系统下禁用usb口
当用户不需要使用usb口时可在系统下通过以下方式禁用usb口:
首先执行lsusb查看识别到的usb设备:
root@localhost:~# lsusb
Bus 003 Device 002: ID 0000:3825 USB OPTICAL MOUSE
Bus 003 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 002 Device 002: ID 1c4f:0026 SiGma Micro Keyboard
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 007 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 006 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 005 Device 004: ID 0781:5591 SanDisk Corp. Ultra Flair
Bus 005 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 004 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
以“Bus 005 Device 004: ID 0781:5591 SanDisk Corp. Ultra Flair”插入的U盘为例执行ls /dev/sd* 可以看到U盘已通过USB口被识别到
root@localhost:~# ls /dev/sd*
sda sda1 sda2 sdc sdc1
此时我们执行以下命令禁用usb口
echo 0 > /sys/bus/usb/devices/usb5/authorized
再次查看usb设备U盘已经不存在了
root@localhost:~# lsusb
Bus 003 Device 002: ID 0000:3825 USB OPTICAL MOUSE
Bus 003 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 002 Device 002: ID 1c4f:0026 SiGma Micro Keyboard
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 007 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 006 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 005 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 004 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
执行“ls /dev/sd*”确认U盘已经看不到了。
root@localhost:~# ls /dev/sd*
/dev/sda /dev/sda1 /dev/sda2
echo 1 > /sys/bus/usb/devices/usb5/authorized
通过lsusb查看usb设备U盘重新被识别到。