sudo taking long time

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


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.


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.