6

Every time I try to execute sudo su - or any other sudo command for this matter my server hangs, sometimes it take 10 mins to respond and sometimes it never does.

I checked /etc/hosts file which was configured correctly. I also checked /etc/resolv.conf file which looked good as well. any suggestions?

I am running redhat 6.9

10
  • So,  do you have any way of becoming root? Oct 28, 2017 at 6:09
  • Yes.. Sometimes it allows me to become root Oct 28, 2017 at 6:10
  • Have you tried running sudo after you’re already root?  Does it still hang then?  If so, you might try running strace (or some similar program) on it. Oct 28, 2017 at 6:15
  • 1
    When does it hang -- before asking for the password or after? (Also, strace sudo -i or so might be your friend, even if its output is daunting, because you can see what it's trying to do when it hangs.) Oct 28, 2017 at 6:16
  • 1
    @GAD3R I think that resolved my issue Oct 28, 2017 at 18:00

6 Answers 6

11

Had the same problem on Ubuntu 16.04 on a newly created openstack remote vm. sudo su hanged for many seconds, maybe up to a minute, before it either worked or not. When it worked it could be made quick and reliable by running this once as root:

echo 127.0.0.1 localhost $(hostname) >> /etc/hosts
2

The problem can reproduced when the hostname is changed , edit your /etc/hosts by adding the output of echo $HOSTNAME after 127.0.0.1:

127.0.0.1  hostname
1
  • I configured it correctly, the issue was fixed but now its back again for no reason. Not sure what the issue is still :( Oct 28, 2017 at 21:29
2

In my case the problem was caused by multiple sudo processes running/hanging in the background, processes like sudo chmod g+rwx -R folders_with_many_files.

What helped was

ps -aleF | grep sudo

first to inspect, later something like

ps -aleF | grep sudo | awk '{print $4}' | xargs kill -9
1
  • Same problem. It solved for me.
    – SmallChess
    Mar 30, 2021 at 12:19
1

In my case this was caused by a missing package. Unfortunately you'll need to use sudo to install it ;) I would recommend sudo su then apt install libnss-myhostname

1
  • This worked for me, with the caveat that I had to modify /etc/nsswitch.conf and place "myhostname" as the first entry in the hosts list. When I installed it was appended to the end of the list by default, so that the "myhostname" method would only be used if all other dns methods failed to resolve the address.
    – David Reed
    May 8 at 0:22
0

I came here after discovering that sudo docker ps would hang forever on my fresh raspberry pi 4 with a ubuntu 20.04.

Putting the value of $HOSTNAME behind 127.0.0.1 in /etc/hosts seemed to have made sudo "more accessible".

But still docker would not run properly. apt upgrade failed for docker also, I couldn't even kill the process with ctrl + c, but had to pkill apt and then kill the process of dpkg by its PID.

Doing sudo dpkg --configure -a as suggested by another ´apt upgrade´, hung at docker-ce package again.

BUT during the first ´apt upgrade´ a new kernel had been installed. So I tried my luck with rebooting. Now it works again. Someone else had a similar experience here: https://askubuntu.com/questions/1236208/docker-ps-stuck-docker-install-also-just-hangs

0

In my case, after removing below config in /etc/sudoers, everything runs ok:

Defaults       use_pty

You must log in to answer this question.

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