2

I'm running Ubuntu 16.04 on my laptop. My son has a Raspberry Pi and uses my laptop to write SD card images as it had an integrated card reader.

Whilst he can mount, format, read and write the cards he cannot write an image without getting me to enter my password. Is there a group I can add him to to allow him to write the image?

My account is in sudoers but I don't want to grant my son's account full superuser rights.

4
  • 4
    It is possible, but you should think twice, because the tools/methods to write an SD image can be used in ways to cause severe damage to your operating system including valuable files. There is a reason why you need sudo for such tasks. -- A simple method is to let your son boot into a live system from an Ubuntu live USB drive, where he can run sudo without any password, only press the Enter key when asked for password. But he will also be able to overwrite your internal drive by mistake.
    – sudodus
    Sep 21, 2019 at 16:13
  • 1
    A solution could be to write a small program that does the job (and uses a hardcoded drive...), make it owned by root, and set its 'suid' bit (so that it always runs with root privs). The catch is that IIRC this requires the program to be an ELF binary, scripts are not allowed for security reasons.
    – xenoid
    Sep 21, 2019 at 16:44
  • Ah right. I'll stick with entering my password - he needs to reimage his Pi on a regular basis so I'm not trusting him with any more privileges than necessary!
    – quorlia
    Sep 24, 2019 at 18:57
  • @xenoid you can provide a proposition of that type of program in answer ;)
    – damadam
    Oct 24, 2019 at 9:42

2 Answers 2

2

If your son is using Etcher, there is no way to prevent privilege escalation because Etcher always tries to escalate privileges when trying to write, even if it doesn't have to.

If he is using dd, you can simply provide user access to the device using a udev rule.

If you want to limit it to a specific SD card, first run the following command with the sdcard inserted:

udevadm info -a /dev/mmcblk0 | grep cid

and note down the value in quotes.

Now create the file /etc/udev/rules.d/50-mmc-uaccess.rules with the following contents:

ACTION=="add", SUBSYSTEM=="block", KERNEL=="mmcblk*", ATTRS{cid}=="[card's cid]", TAG+="uaccess"

Replace [card's cid] with the value you noted down.

If you want to provide access to every SD card, just omit the ATTRS... part:

ACTION=="add", SUBSYSTEM=="block", KERNEL=="mmcblk*", TAG+="uaccess"

Now you can dd to it without sudo.

1
  • gnome-disks also requires privilege escalation, but dd works too.
    – pim
    Oct 24, 2019 at 11:51
1

Q:

Is there a group I can add my son to to allow him to write an image without entering a password?

A:

Yes,it is possible, but you should think twice, because the tools/methods to write an SD image can be used in ways to cause severe damage to your operating system including valuable files. There is a reason why you need sudo for such tasks.

A simple method is to let your son boot into a live system from an Ubuntu live USB drive, where he can run sudo without any password, only press the Enter key when asked for password. But he will also be able to overwrite your internal drive by mistake.

You must log in to answer this question.

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