原文链接:统信UOS/麒麟KYLINOS禁用USB存储
hello,大家好啊,今天给大家带来一篇在统信UOS/麒麟KYLINOS禁用USB存储的文章,文章通过三种方式:1、在文件管理器中通过图形化方式移除USB;2、通过禁用USB存储模块实现禁用;3、通过添加udev规则实现禁用。大家可以选择不同的方式实现,欢迎大家分享转发。关注我吧!
1、查看系统版本
pdsyw@pdsyw-PC:~/Desktop$ cat /etc/os-version
[Version]
SystemName=UOS Desktop
SystemName[zh_CN]=统信桌面操作系统
ProductType=Desktop
ProductType[zh_CN]=桌面
EditionName=Professional
EditionName[zh_CN]=专业版
MajorVersion=20
MinorVersion=1060
OsBuild=11014.100.100
pdsyw@pdsyw-PC:~/Desktop$
pdsyw@pdsyw-PC:~/Desktop$ uname -a
Linux pdsyw-PC 4.19.0-arm64-desktop #6030 SMP Tue Jun 27 15:28:10 CST 2023 aarch64 GNU/Linux
pdsyw@pdsyw-PC:~/Desktop$
2、查看USB存储信息
pdsyw@pdsyw-PC:~/Desktop$ lsmod | grep usb_storage
usb_storage 73728 1
pdsyw@pdsyw-PC:~/Desktop$
3、可以通过卸载按键进行卸载
4、也可以点击安全移除按键进行移除
5、可以通过命令行卸载移除USB
pdsyw@pdsyw-PC:~/Desktop$ sudo rmmod usb_storage
6、移除后查看USB信息
pdsyw@pdsyw-PC:~/Desktop$ lsmod | grep usb_storage
usb_storage 73728 0
pdsyw@pdsyw-PC:~/Desktop$
7、通过禁用usb存储模块实现禁用USB存储
pdsyw@pdsyw-PC:~/Desktop$ sudo -i
root@pdsyw-PC:~# echo "install usb-storage /bin/true" > /etc/modprobe.d/usb-storage.conf
root@pdsyw-PC:~# chmod 644 /etc/modprobe.d/usb-storage.conf
root@pdsyw-PC:~# update-initramfs -u
update-initramfs: Generating /boot/initrd.img-4.19.0-arm64-desktop
cryptsetup: WARNING: The initramfs image may not contain cryptsetup binaries
nor crypto modules. If that's on purpose, you may want to uninstall the
'cryptsetup-initramfs' package in order to disable the cryptsetup initramfs
integration and avoid this warning.
setupcon is missing. Please install the 'console-setup' package.
W: plymouth: The plugin label.so is missing, the selected theme might not work as expected.
W: plymouth: You might want to install the plymouth-themes package to fix this.
I: The initramfs will attempt to resume from /dev/sda3
I: (UUID=9aaca392-458c-4f32-925b-04692d3f9a43)
I: Set the RESUME variable to override this.
live-boot: core filesystems devices utils udev blockdev dns.
Adding IMA binaries
root@pdsyw-PC:~# reboot
8、重新插入u盘已经无法识别
9、通过删除usb-storage.conf文件取消USB存储禁用
pdsyw@pdsyw-PC:~/Desktop$ sudo rm -rf /etc/modprobe.d/usb-storage.conf
pdsyw@pdsyw-PC:~/Desktop$
pdsyw@pdsyw-PC:~/Desktop$ sudo update-initramfs -u
update-initramfs: Generating /boot/initrd.img-4.19.0-arm64-desktop
cryptsetup: WARNING: The initramfs image may not contain cryptsetup binaries
nor crypto modules. If that's on purpose, you may want to uninstall the
'cryptsetup-initramfs' package in order to disable the cryptsetup initramfs
integration and avoid this warning.
setupcon is missing. Please install the 'console-setup' package.
W: plymouth: The plugin label.so is missing, the selected theme might not work as expected.
W: plymouth: You might want to install the plymouth-themes package to fix this.
I: The initramfs will attempt to resume from /dev/sda3
I: (UUID=9aaca392-458c-4f32-925b-04692d3f9a43)
I: Set the RESUME variable to override this.
live-boot: core filesystems devices utils udev blockdev dns.
Adding IMA binaries
pdsyw@pdsyw-PC:~/Desktop$ reboot
10、取消禁用重启后可以识别USB存储
11、通过添加udev规则实现禁用usb存储
pdsyw@pdsyw-PC:~/Desktop$ sudo vi /etc/udev/rules.d/10-usb-block.rules
请输入密码:
验证成功
pdsyw@pdsyw-PC:~/Desktop$ cat /etc/udev/rules.d/10-usb-block.rules
ACTION=="add", KERNEL=="sd[a-z][0-9]*", SUBSYSTEM=="block", RUN+="/bin/sh -c 'echo 0 > /sys/block/%k/device/authorized'"
pdsyw@pdsyw-PC:~/Desktop$ reboot
12、重启后u盘无法识别
13、删除10-usb-block.rules取消禁用
pdsyw@pdsyw-PC:~/Desktop$ sudo rm -rf /etc/udev/rules.d/10-usb-block.rules
请输入密码:
验证成功
pdsyw@pdsyw-PC:~/Desktop$ reboot
14、重启后可以识别u盘