현재 저는 하드 드라이브에서 디스크 이미지를 자주 복사하고 있습니다. 일반적으로 USB를 통해 연결됩니다.
일반적으로 블록 장치는 일반 사용자가 쓸 수 없기 때문에 모든 작업을 루트로 수행합니다. 언젠가 내가 /dev/sda
정말 원하는 사람 에게 편지를 쓰는 실수를 저지르지 않을까 걱정됩니다 /dev/sds
.
GNU/Linux에 "쓰기 방지"를 지시하는 방법이 있습니까 /dev/sda
? 아니면 그룹의 사용자가 모든 USB 블록 장치에 쓸 수 있도록 허용하는 방법이 있을까요 usbwriters
?
보호하고 싶은 블록 장치를 쉽게 나열할 수 있습니다. 하지만 쓰고 싶은 장치는 일반적으로 USB 임시 연결을 사용하기 때문에 나열할 수 없습니다.
다음은 장치 중 하나의 udev 출력입니다.
# /sbin/udevadm info -a -p $(/sbin/udevadm info -q path -n /dev/sdn)
Udevadm info starts with the device specified by the devpath and then
walks up the chain of parent devices. It prints for every device
found, all possible attributes in the udev rules key format.
A rule to match, can be composed by the attributes of the device
and the attributes from one single parent device.
looking at device '/devices/pci0000:00/0000:00:14.0/usb3/3-1/3-1:1.0/host16/target16:0:0/16:0:0:1/block/sdn':
KERNEL=="sdn"
SUBSYSTEM=="block"
DRIVER==""
ATTR{alignment_offset}=="0"
ATTR{capability}=="d1"
ATTR{discard_alignment}=="0"
ATTR{events}=="media_change"
ATTR{events_async}==""
ATTR{events_poll_msecs}=="-1"
ATTR{ext_range}=="256"
ATTR{hidden}=="0"
ATTR{inflight}==" 0 0"
ATTR{range}=="16"
ATTR{removable}=="1"
ATTR{ro}=="0"
ATTR{size}=="13563904"
ATTR{stat}==" 77 0 4168 224 0 0 0 0 0 140 224"
looking at parent device '/devices/pci0000:00/0000:00:14.0/usb3/3-1/3-1:1.0/host16/target16:0:0/16:0:0:1':
KERNELS=="16:0:0:1"
SUBSYSTEMS=="scsi"
DRIVERS=="sd"
ATTRS{blacklist}=="FORCELUN"
ATTRS{device_blocked}=="0"
ATTRS{device_busy}=="0"
ATTRS{dh_state}=="detached"
ATTRS{eh_timeout}=="10"
ATTRS{evt_capacity_change_reported}=="0"
ATTRS{evt_inquiry_change_reported}=="0"
ATTRS{evt_lun_change_reported}=="0"
ATTRS{evt_media_change}=="0"
ATTRS{evt_mode_parameter_change_reported}=="0"
ATTRS{evt_soft_threshold_reached}=="0"
ATTRS{inquiry}==""
ATTRS{iocounterbits}=="32"
ATTRS{iodone_cnt}=="0x81"
ATTRS{ioerr_cnt}=="0x1"
ATTRS{iorequest_cnt}=="0x81"
ATTRS{max_sectors}=="240"
ATTRS{model}=="USB Flash Disk "
ATTRS{queue_depth}=="1"
ATTRS{queue_type}=="none"
ATTRS{rev}=="1100"
ATTRS{scsi_level}=="5"
ATTRS{state}=="running"
ATTRS{timeout}=="30"
ATTRS{type}=="0"
ATTRS{vendor}=="General "
looking at parent device '/devices/pci0000:00/0000:00:14.0/usb3/3-1/3-1:1.0/host16/target16:0:0':
KERNELS=="target16:0:0"
SUBSYSTEMS=="scsi"
DRIVERS==""
looking at parent device '/devices/pci0000:00/0000:00:14.0/usb3/3-1/3-1:1.0/host16':
KERNELS=="host16"
SUBSYSTEMS=="scsi"
DRIVERS==""
looking at parent device '/devices/pci0000:00/0000:00:14.0/usb3/3-1/3-1:1.0':
KERNELS=="3-1:1.0"
SUBSYSTEMS=="usb"
DRIVERS=="usb-storage"
ATTRS{authorized}=="1"
ATTRS{bAlternateSetting}==" 0"
ATTRS{bInterfaceClass}=="08"
ATTRS{bInterfaceNumber}=="00"
ATTRS{bInterfaceProtocol}=="50"
ATTRS{bInterfaceSubClass}=="06"
ATTRS{bNumEndpoints}=="02"
ATTRS{supports_autosuspend}=="1"
looking at parent device '/devices/pci0000:00/0000:00:14.0/usb3/3-1':
KERNELS=="3-1"
SUBSYSTEMS=="usb"
DRIVERS=="usb"
ATTRS{authorized}=="1"
ATTRS{avoid_reset_quirk}=="0"
ATTRS{bConfigurationValue}=="1"
ATTRS{bDeviceClass}=="00"
ATTRS{bDeviceProtocol}=="00"
ATTRS{bDeviceSubClass}=="00"
ATTRS{bMaxPacketSize0}=="64"
ATTRS{bMaxPower}=="300mA"
ATTRS{bNumConfigurations}=="1"
ATTRS{bNumInterfaces}==" 1"
ATTRS{bcdDevice}=="1100"
ATTRS{bmAttributes}=="80"
ATTRS{busnum}=="3"
ATTRS{configuration}==""
ATTRS{devnum}=="29"
ATTRS{devpath}=="1"
ATTRS{idProduct}=="1000"
ATTRS{idVendor}=="090c"
ATTRS{ltm_capable}=="no"
ATTRS{manufacturer}=="General"
ATTRS{maxchild}=="0"
ATTRS{product}=="USB Flash Disk"
ATTRS{quirks}=="0x0"
ATTRS{removable}=="removable"
ATTRS{serial}=="FBK1611110100145"
ATTRS{speed}=="480"
ATTRS{urbnum}=="981"
ATTRS{version}==" 2.00"
looking at parent device '/devices/pci0000:00/0000:00:14.0/usb3':
KERNELS=="usb3"
SUBSYSTEMS=="usb"
DRIVERS=="usb"
ATTRS{authorized}=="1"
ATTRS{authorized_default}=="1"
ATTRS{avoid_reset_quirk}=="0"
ATTRS{bConfigurationValue}=="1"
ATTRS{bDeviceClass}=="09"
ATTRS{bDeviceProtocol}=="01"
ATTRS{bDeviceSubClass}=="00"
ATTRS{bMaxPacketSize0}=="64"
ATTRS{bMaxPower}=="0mA"
ATTRS{bNumConfigurations}=="1"
ATTRS{bNumInterfaces}==" 1"
ATTRS{bcdDevice}=="0415"
ATTRS{bmAttributes}=="e0"
ATTRS{busnum}=="3"
ATTRS{configuration}==""
ATTRS{devnum}=="1"
ATTRS{devpath}=="0"
ATTRS{idProduct}=="0002"
ATTRS{idVendor}=="1d6b"
ATTRS{interface_authorized_default}=="1"
ATTRS{ltm_capable}=="no"
ATTRS{manufacturer}=="Linux 4.15.0-96-generic xhci-hcd"
ATTRS{maxchild}=="4"
ATTRS{product}=="xHCI Host Controller"
ATTRS{quirks}=="0x0"
ATTRS{removable}=="unknown"
ATTRS{serial}=="0000:00:14.0"
ATTRS{speed}=="480"
ATTRS{urbnum}=="918"
ATTRS{version}==" 2.00"
looking at parent device '/devices/pci0000:00/0000:00:14.0':
KERNELS=="0000:00:14.0"
SUBSYSTEMS=="pci"
DRIVERS=="xhci_hcd"
ATTRS{broken_parity_status}=="0"
ATTRS{class}=="0x0c0330"
ATTRS{consistent_dma_mask_bits}=="64"
ATTRS{d3cold_allowed}=="1"
ATTRS{device}=="0x1e31"
ATTRS{dma_mask_bits}=="64"
ATTRS{driver_override}=="(null)"
ATTRS{enable}=="1"
ATTRS{irq}=="24"
ATTRS{local_cpulist}=="0-7"
ATTRS{local_cpus}=="ff"
ATTRS{msi_bus}=="1"
ATTRS{numa_node}=="-1"
ATTRS{revision}=="0x04"
ATTRS{subsystem_device}=="0x0686"
ATTRS{subsystem_vendor}=="0x1025"
ATTRS{vendor}=="0x8086"
looking at parent device '/devices/pci0000:00':
KERNELS=="pci0000:00"
SUBSYSTEMS==""
DRIVERS==""
답변1
루트 공격으로부터 장치를 보호하는 대신 다음 규칙을 사용하여 이동식 USB 장치 노드가 usbwriters
그룹별로 쓰기 가능 하도록 보장합니다.udev
KERNEL=="sd[a-z]*", ATTR{removable}=="1", SUBSYSTEMS=="usb", MODE="660", GROUP="usbwriters"
어딘가에 추가하고 /etc/udev/rules.d
(로컬 규칙 파일이 있음 01-local.rules
) 사용하는 그룹에 자신을 추가하십시오.
답변2
해결책은 "/etc/udev/rules.d/99-local.rules"에 다음 줄을 추가하는 것입니다.
KERNEL=="sd[a-z]*", SUBSYSTEMS=="usb", MODE="660", GROUP="plugdev"
@StephenKitt의 답변에 대한 변형은 다음과 같습니다.
- 삭제 중
ATTR{removable}=="1"
.ATTR{removable}=="1"
partition( )이 포함되어 있으면/dev/sdn1
영향을 받지 않습니다. - 01-local... 대신 99-local...로 설정하십시오. 그렇지 않으면 그룹이 50-...으로 덮어쓰기되기 때문입니다.
( udevadm test $(udevadm info -q path -n /dev/sdn)
이 문제를 해결하는 데 절대적으로 중요합니다. @StephenKitt에게 감사드립니다).