我想使用udev规则阻止除键盘和鼠标之外的所有USB设备?

时间:2018-10-25 07:44:38

标签: usb ubuntu-16.04 external udev

我想使用udev规则阻止除USB键盘和USB鼠标之外的所有USB设备?目的是限制用户连接外部存储设备(闪存驱动器,电话内部存储和iOS设备存储)。

限制用户从16.04及更高版本的Ubuntu计算机上将数据传输到这些设备。

限制mtp移动传输协议以及限制照片传输。

使用终端中的sudo权限登录到计算机。

# Sudo –i 
List the usb ports:
#lsmod |grep usb 
Edit the blacklist.conf file
# Sudo vi /etc/modeprobe.d/blacklist.conf 
blacklist usb_storge
blacklist uas
blacklist usbhid
#Sudo vi /etc/rc.local/ 
modprobe -r usb_storage 
modprobe -r uas
modprob usbhid

保存重新启动机器。 但是移动存储如何管理如何将存储连接到计算机。
,所以现在尝试udev规则,我已经尝试对所有端口(usb / 1-3,usb1 / 1-3 ..)进行跟踪,但是它会阻止kb鼠标

#echo 0 > / sys/bus/usb/devices/1-3/authorized 

我尝试过的其他选项:

/etc/udev/rules.d/01-usblockdown.rules
The contents of the script are as follows:
#Script by Adrian Crenshaw
#With info from Michael Miller, Inaky Perez-Gonzalez and VMWare

#By default, disable it.
#ACTION=="add", SUBSYSTEMS=="usb", RUN+="/bin/sh -c 'echo 0 >/sys$DEVPATH/authorized'"<br>
ACTION=="add", SUBSYSTEMS=="usb", RUN+="/bin/sh -c 'for host in /sys/bus/usb/devices/usb*; do echo 0 > $host/authorized_default; done'"

#Enable hub devices. There may be a better way than this.
ACTION=="add", ATTR{bDeviceClass}=="09", RUN+="/bin/sh -c 'echo 1 >/sys$DEVPATH/authorized'"

#Other things to enable
ACTION=="add", ATTR{idVendor}=="046d", ATTR{idProduct}=="0809", RUN+="/bin/sh -c 'echo 1 >/sys$DEVPATH/authorized'"
ACTION=="add", ATTR{serial}=="078606B90DD3", RUN+="/bin/sh -c 'echo 1 >/sys$DEVPATH/authorized'"
ACTION=="add", ATTR{product}=="802.11 n WLAN", RUN+="/bin/sh -c 'echo 1 >/sys$DEVPATH/authorized'"
#ACTION=="add", ATTR{idVendor}=="413c", ATTR{idProduct}=="2106", RUN+="/bin/sh -c 'echo 1 >/sys$DEVPATH/authorized'"

它也阻止了USB键盘和鼠标。

0 个答案:

没有答案