Sudo command hangs
Solution 1
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
Solution 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
Solution 3
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
Related videos on Youtube
![Ahmed Soliman](https://lh4.googleusercontent.com/-rZ-OUVOPKmc/AAAAAAAAAAI/AAAAAAAAEAA/g5dh0O7C8lM/photo.jpg?sz=256)
Ahmed Soliman
Updated on September 18, 2022Comments
-
Ahmed Soliman almost 2 years
Every time I try to execute
sudo su -
or any othersudo
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
-
Admin over 6 yearsSo, do you have any way of becoming root?
-
Admin over 6 yearsYes.. Sometimes it allows me to become root
-
Admin over 6 yearsHave you tried running
sudo
after you’re already root? Does it still hang then? If so, you might try runningstrace
(or some similar program) on it. -
Admin over 6 yearsWhen 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.) -
Admin over 6 yearsPossibly related: unix.stackexchange.com/questions/365599/…
-
Admin over 6 years@UlrichSchwarz
strace
is usually a good idea and I almost suggested this myself, but sincesudo
has thesetuid
bit set,strace
will (should) not be able to attach :-| @Ahmed: if you eventually manage to get root, does it also hang when you dosudo -u $someuser -i
? If so, then try that withstrace
. -
Admin over 6 yearsDo you have PAM installed. If so, check the config files if you're using some kind of remote authentification (e.g., LDAP)
-
Admin over 6 yearsOn your
/etc/hosts
you shoud have127.0.0.1 hostname
;hostname
=echo $HOSTNAME
-
Admin over 6 years@GAD3R I think that resolved my issue
-
-
Ahmed Soliman over 6 yearsI configured it correctly, the issue was fixed but now its back again for no reason. Not sure what the issue is still :(
-
SmallChess about 3 yearsSame problem. It solved for me.