6

On a Ubuntu 9 64bit Linux machine, sudo takes longer time to start. "sudo echo hi" takes 2-3 minutes. strace on sudo tells poll("/etc/pam.d/system-auth", POLLIN) timesout after 5 seconds and there are multiple calls(may be a loop) to same system call (which causes 2-3min delay).

Any idea why sudo has to wait for /etc/pam.d/system-auth? Any tunable to make sudo to timeout faster?

Thanks Samuel

3 Answers3

20

The largest cause of sudo being slow is the system not being able to resolve it's own hostname. Do you have your local hostname included in /etc/hosts? If not I would recommend adding it with the IP 127.0.1.1 which is what I do on all my systems. I add the entry with both the short hostname and the full qualified domain name (FQDN). This then removes the delay in sudo access calls 9 out of 10 times.

Jeremy Bouse
  • 11,341
  • 2
  • 28
  • 40
1

I can't help but think that the poll() call may be a red herring.

Whenever I have seen sudo being exceptionally slow, it has always been DNS that is at fault. Whether it's old, dead servers listed in /etc/resolv.conf or a misconfigured firewall that's blocking port 53 outbound or something else entirely, I have always found that dig google.com is slow when sudo echo foo is slow.

Even if it is not DNS, I suspect the slowness is network related and possibly authentication related (as Kevin M suggested) in which case the poll() call may not be a red herring after all.

Try running a tcpdump while trying to run sudo and see what shows up.

Ladadadada
  • 26,337
  • 7
  • 59
  • 90
1

In my case restarting systemd-logind solved (temporarily) the problem.

sudo systemctl restart systemd-logind
  • Where you able to find a permanent solution, and/or a root cause? If so, could you share? I suspect the poster might prefer a more permanent solution, even though yours might help in an emergency. – iwaseatenbyagrue Mar 04 '17 at 13:23
  • I would also prefer a permanent solution but I've yet nothing better to propose. – Ortomala Lokni Mar 04 '17 at 13:51
  • And how do you restart systemd-logind on a non-systemd system? I just ran into sudden sudo slowdown (DNS works perfectly, I *checked*) and I do have this stupid process running but my init is still init. – Jürgen A. Erhard Nov 14 '18 at 23:18
  • I think you should ask a new question for this, describing precisely your problem, what you tries and the results you obtain. – Ortomala Lokni Nov 15 '18 at 08:54