Internet, IT and Technology

SUDO command execution awfully slow on Linux

What to do if the sudo command runs very slowly on Linux, when combined with any other command.
Linux hostname

The sudo command in Linux is one of the most used by most users, and it is already installed in practically any distribution such as Debian, Ubuntu, or Linux Mint. This command is essential for running tasks that require elevated privileges.

Speed up slow execution of sudo command

Context

There is a certain configuration in which sudo becomes really slow, the normal time is a duration of milliseconds to ask for the password, which is practically in no time, and it is when the hostname of our installation is not properly configured in the hosts file. This can occur when we change the name of our computer, commonly called hostname.

Problem solution

First we have to check the name of our computer, we execute the following command.

Note: in some cases, it is necessary to run the command with the -f parameter. Mainly on web servers or remotely managed servers.

hostname

# if it is a server or similar
hostname -f

To solve it, we only need to edit the hosts file and look for the entry that has the IP address 127.0.1.1. If it does not exist, we create it, and if it already exists, we change the content respecting the following format, IP address, followed by some spaces and followed by the computer name.

sudo nano /etc/hosts

The output of the hostname command is what should be in the hosts file.

Example:

127.0.0.1 localhost
127.0.1.1 L5-DE60-7405

It is usually located at the beginning of the file and should not be confused with localhost, which is quite similar.

Linux nano hosts

Categories

Related content