Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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 am trying to change the hostname of a Gentoo host using a sudoer account. I use the following procedure :

  1. sudo rm -f /etc/conf.d/hostname
  2. sudo touch /etc/conf.d/hostname
  3. sudo echo "hostname=foo" >> /etc/conf.d/hostname
  4. sudo /etc/init.d/net.lo restart

Only the step 3 fails. It raises a permission error. So I would like to know why I get this ? I tried to stop the networking service first, but no change.

share|improve this question

It fails because the >> is interpreted by the normal user's shell; only the echo is run as root.

A simple way around this is to run the command in an interactive root shell:

$ sudo su -
# echo "hostname=foo" > /etc/conf.d/hostname
# /etc/init.d/net.lo restart
# exit

Note that you don't need the touch command, and if you just use > you can also do without the rm, as > will overwrite the file's contents.

share|improve this answer

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.