sudo taking long time
Solution 1
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.
Solution 2
In my case restarting systemd-logind solved (temporarily) the problem.
sudo systemctl restart systemd-logind
Solution 3
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.
Related videos on Youtube
![Admin](/assets/logo_square_200-5d0d61d6853298bd2a4fe063103715b4daf2819fc21225efa21dfb93e61952ea.png)
Admin
Updated on September 17, 2022Comments
-
Admin almost 2 years
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
-
iwaseatenbyagrue over 7 yearsWhere 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.
-
Ortomala Lokni over 7 yearsI would also prefer a permanent solution but I've yet nothing better to propose.
-
Jürgen A. Erhard over 5 yearsAnd 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.
-
Ortomala Lokni over 5 yearsI think you should ask a new question for this, describing precisely your problem, what you tries and the results you obtain.