1

I am new to this and need help I got this error and need step by step instructions

sudo: unable to resolve host legend27

I am running Ubuntu 16.04

  • 1
    legend27@legend27:~$ /etc/hostname bash: /etc/hostname: Permission denied i get this error also. – Sock Guy Jan 13 '18 at 06:13
  • 2
    Welcome to Ask Ubuntu! The best way to add additional information to your question is by editing it, with the edit button. It is better visible that way, and comments are mainly for secondary, temporary purposes. Comments are removed under a variety of circumstances. Anything important to your question should be in the question itself. – J. Starnes Jan 13 '18 at 06:52
  • Please update your question with output of hostnamectl. – N0rbert Jan 13 '18 at 16:30

2 Answers2

3

Do you have your hostname entry present in /etc/hosts like this?

127.0.0.1  legend27

And BTW, /etc/hostname is a file which needs to be edited, not a command to be executed.

$ /etc/hostname # Executes /etc/hostname as a command; wrong way to do it
$ gedit /etc/hostname # Opens /etc/hostname for editing, right way to do it

You get that "Permission denied" error because /etc/hostname doesn't have the execute bit set on its file permissions, and it is not intended to be executed anyway.

0

Everybody advises to modify /etc/hosts. But in some cases this may not be possible (for example inside a docker container). So, I had to find a better way and I came up with this:

echo "alias sudo='sudo -h 127.0.0.1'" >> ~/.bash_aliases
source ~/.bashrc

Aliases don't work in bash scripts, but we can use variables: sudo='sudo -h 127.0.0.1'