8

I need to create an image of a partition of a usb drive:

dd if=/dev/sdb1 of=sdb1.img

Is there a way to do it without sudo/su? Maybe by changing permissions on the usb drive? What would be the security implications?

3
  • What are you trying to do? If you are trying to allow users on a multiuser system to image a specific disk, one solution could be to run dd if=/dev/sdb1 as a root user (or present it in some secure way with a suid binary), with a normal user redirecting the output into a file of their choice.
    – Cyclic3
    Commented May 3, 2020 at 13:45
  • This doesn't solve the permission issue, but note that you don't need dd for this, you could just do sudo cat /dev/sdb1 > sdb1.img.
    – terdon
    Commented May 3, 2020 at 15:47
  • I ma trying to image a small partition on a specific usb drive to back it up online. Having to sudo is annoying.
    – Piero dS
    Commented May 3, 2020 at 15:49

2 Answers 2

6

Is there a way to do it without sudo/su? Maybe by changing permissions on the usb drive?

If your /dev/sdb1 has permissions like:

$ ls -l /dev/sdb1
brw-rw---- 1 root disk 8, 17 Apr 25 17:07 /dev/sdb1

Then an option would be to add your user to the disk group:

# usermod --append --groups disk username

After that, the next time that the user logs in, they'll be able to read the device. Your dd should work after that.

What would be the security implications?

Since the user can read any disk directly, the user would have access to files owned by any user on any disk.

The user would be able to not only read any disk, but would also be able to write directly to any block device file with the same permissions (g+rw). That user could easily corrupt any filesystem by accidentally writing to those block device files. Changing permissions to disallow the disk group write permissions might have other side effects that I can't predict.

As a result, if you're on a multi-user system or on a system where you care about data stored on any disk, I don't recommend you do this. Normal users aren't given access to block devices because of the security implications.

2
  • 4
    Note that this likely gives read/write access to all disks, not just the USB drive. Seems like kind of an important detail, especially considering that the OP is asking about security implications ;)
    – marcelm
    Commented May 3, 2020 at 12:08
  • 1
    @marcelm good call. I've updated my answer to clarify that this approach applies to any disk. Commented May 3, 2020 at 17:44
1

Since it's a USB drive and presumably portable, the obvious workaround I ended up using before was to create the image on a machine where you do have sudo access, and then move the image file to the target system afterwards (possibly on a larger USB drive)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .