Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

1 Answer 1

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

 
discard

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.