3

Attempting to set up an SSH-server running Ubuntu 12.04. Went to "HowToForge" to scout for potentially advanced or knowledgeable advice upon how to accomplish this, then I ended up running into a problem; off of one of their "Perfect Server Setup" how-to's, I am hitting a point where the instructions want me to echo the following command to /etc/hostname:

echo server1.example.com > /etc/hostname

then the following error is thrown:

-bash: /etc/hostname: Permission denied

Great, don't know why, I should have administrative privileges. Then I tried to see whether /etc/hostname is writable via lsattr, and I get:

-------------e- /etc/hostname

Last time I checked, this implied that my file was not immutable.

In either case, what is happening, and what am I doing wrong?

Zanna
  • 72,312

2 Answers2

4

You'll need administrative privileges to edit a file which is not owned by you. To execute the command echo server1.example.com > /etc/hostname, you will have to do the following:

sudo -i

enter your password if you are the administrator or if you are not, ask the administrator to enter the password

and then

echo server1.example.com > /etc/hostname
guntbert
  • 13,475
jobin
  • 28,567
1

For scripting purpose, you could use tee to have the administrator rights to write the file:

echo server1.example.com | sudo tee /etc/hostname > /dev/null 2>&1