Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can solve this problem at the operating system level by changing access rights to the disk. This may be superior to using sudo every time you run your script because you don't have to muck around with passwords or worry that your script goes crazy and wipes out your system.</p> <p>Sorry if I'm being a bit basic here, but linux uses file permissions to decide how users can access files in the file system. On my machine:</p> <pre><code>$ ls -l /dev/sda2 brw-rw---- 1 root disk 8, 2 Jun 27 15:04 /dev/sda2 </code></pre> <p>The device is owned by 'root' (the super user) and is in the 'disk' group. root and anybody in the disk group can access the device. But 'others' (everybody else) is blocked.</p> <pre><code>$ dd if=/dev/sda2 of=/dev/null bs=1 dd: opening `/dev/sda2': Permission denied </code></pre> <p>I'm not root and i'm not in the disk group, so the dd fails. I could add myself to the 'disk' group, but that's granting a lot of rights and runs the risk that evil will happen. </p> <p>What we've seen so far are standard *nix rights, but most modern linux file systems support extended rights. I can give myself rights to read the device</p> <pre><code>$ sudo setfacl -m u:td:r /dev/sda2 [sudo] password for td: </code></pre> <p>Now, if I list the device I see a plus sign on the rights string meaning there are extended acls that I can also view</p> <pre><code>$ ls -l /dev/sda2 brw-rw----+ 1 root disk 8, 2 Jun 27 15:04 /dev/sda2 $ getfacl /dev/sda2 getfacl: Removing leading '/' from absolute path names # file: dev/sda2 # owner: root # group: disk user::rw- user:td:r-- group::rw- mask::rw- other::--- </code></pre> <p>And dd works! </p> <pre><code>$ dd if=/dev/sda2 of=/dev/null bs=1 1024+0 records in 1024+0 records out 1024 bytes (1.0 kB) copied, 0.0146606 s, 69.8 kB/s </code></pre> <p>Notice that this is far safer (script can read /dev/sda2) than sudo (script can do everything). I could let other people I don't trust very much use this script by giving them rights to the block device without giving them the keys to the kingdom.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload