Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to run the following command without the need for sudo:

echo 1 | sudo tee -a /sys/block/$hd/device/delete

The $hd variable changes dynamically from sdb -> sdi for each one of my HDD's in my drive bay.

I added the following line to the sudoers file:

operator ALL=/sys/block/sdb/device/delete

But this didn't make a difference its still asking for sudo password even if I run:

echo 1 | sudo tee -a /sys/block/sdb/device/delete
share|improve this question

migrated from Oct 25 '12 at 5:00

This question came from our site for professional and enthusiast programmers.

Not a programming question. – Steve-o Oct 24 '12 at 14:13
Perhaps a Serverfault question? – rmarimon Oct 24 '12 at 14:16
up vote 4 down vote accepted

The sudoers line can only point to the command you're intended to run, not the destination output file. Anything under that /sys is a special device that characters are written to.

What you want to do is create a script that will do echo 1 > /sys/block/$hd/device/delete where $hd is checked to match the regular expression /sd[b-i]/. Point the sudo command at that script rather than where you have it.

Also, Michael Hampton is right: somebody will run a delete command you don't want mess things up. If you don't have proper backups, then your data never existed.

share|improve this answer

Put your code in a script (you ARE writing a script, right?) and grant the user sudo access to the script.

It'll probably end up looking something like this:

for kill_this_disk in /sys/block/sd[b-i]/device/delete
    echo 1 > $kill_this_disk

And, I hope you have good backups.

share|improve this answer

I don't think *operator ALL=/sys/block/sdb/device/delete * will enable you to access that device even as non root. The sudoers enables you to specify commands which will not query for the password when ran as sudo (here "tee" for example). Your problem comes from permissions on the /sys/block/$hd/device/delete...

share|improve this answer

Perhaps you need to use the NOPASSWD option in the sudoers configuration file. I believe the syntax is something like this:

operator ALL=NOPASSWD:/sys/block/sdb/device/delete
share|improve this answer
-1. Sudo specifies the command to run. This is the system object file that is being written to. – Jeff Ferland Oct 25 '12 at 5:25

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.