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?
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.
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)
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.dd
for this, you could just dosudo cat /dev/sdb1 > sdb1.img
.