I noticed that the terminal recently becomes too slow when I execute a command that needs my password. It takes some seconds to display [sudo] password for ...

  • Hi, could you add a bit more information to your question please. What OS are you using and is it 32 or 64-bit? – SimplySimon Jul 21 '13 at 10:04
  • What hardware do you have – Alvar Jul 21 '13 at 10:11
  • I'm using Dell XPS developer edition (i7,8g ram) with ubuntu 13.04 64bit. – Nasreddine Jul 21 '13 at 10:26
  • 1
    It's very strange, but, I receive "Ubuntu could not resolve the host" when connection isn't available. I execute this command "echo 0 | sudo tee /sys/class/backlight/intel_backlight/brightness " – Nasreddine Jul 25 '13 at 4:30
  • 2

Hi I found this answer on another question - The problem is if your hostname is not in your hosts file.

basically, type "hostname" in your terminal. That will tell you what your hostname is.

Next, type:

sudo nano /etc/hosts

and add: yourhostname

then save - and you are done! Sudo should be fast now!

| improve this answer | |
  • This post I guess ? : serverfault.com/questions/38114/… – monojohnny Mar 24 '16 at 0:19
  • I have the feeling that it can also be caused by DNS setting in NetworkManager: askubuntu.com/questions/898605/… – tobias47n9e Aug 8 '18 at 8:16
  • 4
    This is still valid in ubuntu 18.04. Thanks – Alexandre Neto Aug 17 '18 at 10:25
  • @Paul Preibisch, I have the same issue in mac. How can i get the host name? – unknownerror Mar 17 at 16:02
  • 1
    Can there be another reason? Because I do have my hostname in /etc/hosts and it takes 25 seconds for the password prompt to appear. Makes productive work impossible. – panzi Mar 24 at 17:14

When you change your systems name in Gnome (The part that is displayed in the terminal after the @; e.g. tobias@laptop to tobias@newlaptop you might need to update your /etc/hosts: laptop

needs to be changed to newlaptop

If you get it right sudo should work without delay immediately after saving this setting.

| improve this answer | |

Confirmed @Paul Preibisch answer for those who wants more detailed answer

I had this issue for a long time and all I did was to run

hostnamectl | grep -i "static hostname"

this will show you your hostname then copy the value and edit your hosts

sudo vim /etc/hosts

and add yourHostName to it

| improve this answer | |
  • This is the best, elegant and most valuable response to the question. – Raiden Core Aug 30 at 23:06
  • Running hostnamectl, I get "Failed to query system properties: Connection timed out". The hostname returned by hostname already has a entry in /etc/hosts, but the problem persists. – appas Sep 16 at 4:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.