15

Whether I get prompted for a password or not, it hangs between accepting the authentication and executing what I asked for. In other words sudo ls will hang for about 60 seconds.

I'm confused about what might be causing this. This is on Centos 5, and I've looked at selinux and set it both to disabled and enabled, but it doesn't seem to have any effect.

8 Answers 8

21

From @TheAndruu's answer to this question:

This happens if you change the hostname during the install process. To solve the problem, edit the file /etc/hosts

127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 [ADD_YOURS_HERE] 
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6 [ADD_YOURS_HERE]

I had exactly the same problem on Fedora 11 and this solved it.

5
  • 1
    I just made sure that my $HOSTNAME was set in the 127.0.0.1 line. It worked. Thanks.
    – dlamblin
    Sep 15, 2009 at 0:59
  • 2
    BTW sudo ls uses the network in what way?
    – dlamblin
    Feb 7, 2017 at 10:49
  • This also worked for ubuntu 16.04 - except I had to change the name for 127.0.1.1 - 127.0.0.1 was localhost
    – Bill Ryder
    Oct 7, 2017 at 1:34
  • This also worked for PopOS 22.04 (Ubuntu 22.04) Sep 2, 2023 at 0:26
  • And I have not changed hostname neither during nor after the install. I suspect some package must have edited the hosts file? Sep 2, 2023 at 0:27
2

For me it was krb5-user/config being installed. I noticed this by examining /var/log/auth.log and seeing pam_krb5 attempts before pam_unix. Using apt-get remove to uninstall those packages fixed it. Don't remove those packages if you are on a computer requiring kerberos (pam_krb5) obviously. My sudo hang went from a consistent 30s to 0s.

2

This is hinted at in [Halsafar][1]'s [answer][2], I have Kerberos enabled on my work VPN but it's useless when I'm off it, so I changed the auth module order in /etc/pam.d/common-auth to use pam_unix before pam_krb5:

Before:

auth [success=4 default=ignore] pam_krb5.so ...
auth [success=3 default=ignore] pam_unix.so ...

After:

auth [success=4 default=ignore] pam_unix.so ...
auth [success=3 default=ignore] pam_krb5.so ...

Note that we change the success= numbering to reflect the new order.

This changed my sudo from 30s to 0s as it did in Halsafar's answer. [1]: https://serverfault.com/users/127821/halsafar [2]: https://serverfault.com/a/495196

1
  • 1
    Changing the success=# numbering is essential too, by the way. After that it worked flawless again. Thanks!
    – Haini
    May 10, 2023 at 21:26
1

Sometimes when your default route isn't set, commands like sudo hang.

Try netstat -r to check if the route is set correctly.

Does this machine get its passwords from the local /etc/passwd file or something like ldap?

2
  • It is not using ldap; I think it is using /etc/passwd
    – dlamblin
    Sep 15, 2009 at 0:47
  • /etc/passwd isn't used for auth, it's used for id to name resolution. /etc/shadow is used for authentication.
    – LiraNuna
    Sep 15, 2009 at 2:09
1

The only other thing you may want to check is your /etc/resolv.conf file to make sure you have a proper dns entry in there. I have seen in the past where this can cause delay.

1
  • 1
    Would you be able to give an example of what a proper DNS entry in /etc/resolv.conf might look like? May 11, 2020 at 2:37
1

You should check three things. 1. /etc/hostname 2. /etc/hosts 3. /etc/resolv.conf

I found that my hostname was correct that the hosts file was incorrect and on top of that the resolv.conf needed updating.

1
  • 2
    @PaulJBarrett, how exactly did you update your resolv.conf to fix the issue? And in what way was the hosts file incorrect? May 11, 2020 at 2:40
0

On Solaris 10 sudo was hanging for about 30 seconds. With help from truss I was finally able to determine that it was hanging on the quota command which was hanging on an NFS mount. Unmounting the NFS share eliminated the hang. Have not determined what is wrong with the share yet.

0

In Fedora 30, Snapd causes sudo, su, etc, to become very slow, and also other session related problems.

Uninstalling snapd, if you're at Fedora, is a recommended alternative.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .