8

I just did a fresh install of Ubuntu and now when I try to use sudo in the terminal emulator, it just hangs there without even asking me for a password. If I switch to the terminal (Ctrl + Alt + F1) and login, sudo works as expected. Can someone help me to figure this out?

  • Just a thought, have you changed the character encoding of your terminal (Open Terminal, menu Terminal -> Set Character Encoding) – hytromo Jul 29 '13 at 19:21
  • No, I haven't, but I am curious as to why that would change anything. – Lawrence Jul 29 '13 at 19:53
  • It can be the source of many problems if you change something like this, actually. But this was just a guess. – hytromo Jul 29 '13 at 20:18
  • I had the same problem. Changing from kernel 4.9 to 4.4 solved it for me. – Tom Hale Jan 3 '17 at 21:31
18

Have you changed the hostname recently? I've noticed after a hostname change sudo can hang for a bit. However, if you update your hosts file to reflect the hostname change the hang will go away.

You can do that with this simple one-liner:

hostname | (echo -n "127.0.0.1        " && cat) | sudo tee -a /etc/hosts
  • 1
    It does not hang for 'a bit', it just hangs indefinitely. Also, it works on the terminal, just not in the terminal emulator. – Lawrence Jul 29 '13 at 19:54
  • This was the exact problem! Thank you! – Nemanja Boric Mar 24 '15 at 16:52
  • 1
    Give this man a cookie! Thanks when changing the Device Name in Ubuntu's system details utility you effectively break sudo. Great work @Canonical. – Flatron Feb 1 '17 at 7:32
  • 1
    to fix it make sure to change /etc/hosts also to your new hostname ;) – Flatron Feb 1 '17 at 7:32
  • Great! I didn't actually notice that it timed out after ~30 sec and then continue with asking for sudo password. Another point: when you is about to change your hostname (maybe you cloned a VM) you might be disconnected to any network to avoid conflicts until you have change the entries. That's is properly also what's causing the timeouts – Hulvej Apr 23 '18 at 8:18
4

If you want to check where it hangs, I suggest doing the executing the following command:

 strace sudo 

and then see what system call it is possibly hanging on. This might provide a good clue as to what is happening on your system.

My guess based on what you see is that hostname resolution is problematic on your system. Check out /etc/nsswitch.conf and /etc/resolv.conf files to make sure they are configured properly.

I have assummed that you have already checked your internet connectivity.

  • 1
    Why is internet connectivity required for sudo? – grofte Jun 17 '17 at 7:05
  • for FQDN information...as you can put host restrictions in your sudoers file. – mdpc Jun 20 '17 at 18:04
  • I did not understand that. I only know that it makes it tricky to reset the wifi adapter. Which is sometimes necessary after putting the laptop in sleep. – grofte Jun 25 '17 at 6:20
1

I am not sure which version of ubuntu you have installed, but there is a bug (race condition) in sudo, which hangs indefinitely blocking on a select.

https://bugzilla.sudo.ws/show_bug.cgi?id=447

0

I too had this problem with Ubuntu 16.04 . Using "top" command i found that two processes "vnstat" and "NetworkManager" are consuming 100% CPU. So i restarted the system, went to recovery mode and removed the package "vnstat" . After this restarted the system , now system works fine.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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