3

I changed the hostname from default name, set during installation to something short and nice, but didn't change it in /etc/hosts file. /etc/hostname is changed after restart but sudo is not working.

I tried to search for answers on internet. Everybody is suggesting to edit /etc/hosts file and replace:

127.0.1.1 <previous name> 

to:

127.0.1.1 <new name> 

but I cannot change this file either by using:

sudo gedit /etc/hosts

It gives an error:

sudo:unable to resolve host <new-name>
JoKeR
  • 6,972
  • 9
  • 43
  • 65
Rookie
  • 33
  • Have you checked this ? possible duplicate of http://askubuntu.com/questions/59458/error-message-when-i-run-sudo-unable-to-resolve-host-none – Aravinda Apr 19 '15 at 10:27
  • since you are having issues, with sudo try to fix it using recovery mode.. http://askubuntu.com/questions/150367/how-do-i-boot-into-recovery-mode – Aravinda Apr 19 '15 at 10:36
  • You can try starting your computer using a live USB/DVD/CD (preferably using Ubuntu or one of the derivatives) and then editing that hosts file with root privileges from there. – Sadi Apr 19 '15 at 10:44
  • 1
    You can open a commandline editor like nano in terminal with pkexec instead of sudo. Try this and tell me if it worked, please. – Byte Commander Apr 19 '15 at 10:52
  • thanks @Aravinda it looks like the answer to my problem, i am gonna give it a try. – Rookie Apr 19 '15 at 10:58
  • @ByteCommander your method was the best, it worked like a charm, Thanks :) – Rookie Apr 19 '15 at 11:02

1 Answers1

7

If sudo and its graphical derivates gksu and gksudo are not working any more, the easiest solution is to use pkexec instead to open a command-line editor like nano and correct the wrong entries in the specific configuration files (like /etc/hosts or /etc/sudoers).

Note that pkexec works for terminal applications, but needs special configuration to run GUI programs. Therefore you need to use nano instead of gedit, mousepad or whatever your default editor is...

Byte Commander
  • 107,489
  • @MehranAli I converted my comment into an answer as you wrote it solved you problem. Please accept it by clicking on the grey tick right below the vote count on the left. This means "Yes, this is a good answer and solved my problem". Thank you! :-) – Byte Commander Apr 19 '15 at 11:09
  • gksudo no longer works as far as I can tell... I think the new thing to use is sudo -i (although no doubt it will change in a few years :P – Tim Apr 19 '15 at 11:48
  • @Tim gksu and gksudo work for me on 14.10 Ubuntu plus XFCE... – Byte Commander Apr 19 '15 at 12:14