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.
Table of Contents
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.
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.