Follow these steps to install and configure `sudo` on your Linux system. This will allow you to execute commands with superuser privileges.
Before you begin installing and configuring `sudo` on your Linux system, ensure you have the following:
Access to a Linux server with root privileges: You'll need administrative access to the Linux server to install and configure `sudo`.
User Account: Make sure you have a user account on the system with `sudo` privileges or the ability to become `root`. This account will be used to proceed with the installation and configuration of `sudo`.
If you require assistance with setting up these prerequisites, you can refer to the following tutorials:
The following steps apply to both Debian and Ubuntu systems.
To perform administrative tasks, you must first connect to your root user. If you're logged in as a non-root user, switch to the root user using:
Linux (Debian/Ubuntu)
su -
Enter the root password when prompted.
First, update the package list to ensure you have the latest information about available packages.
Linux (Debian/Ubuntu)
apt update
Install the `sudo` package.
Linux (Debian/Ubuntu)
apt install sudo
Verify that `sudo` is installed correctly by running the following command, which should return `root`:
Linux (Debian/Ubuntu)
sudo whoami
Check if the `sudo` group exists on your system.
Linux (Debian/Ubuntu)
getent group sudo
Add your user to the `sudo` group to grant `sudo` privileges. Replace `your_username` with your actual username.
Linux (Debian/Ubuntu)
usermod -aG sudo your_username
If you encounter the error bash: usermod: command not found, it means the `usermod` command's path might not be in your PATH variable. Follow these additional steps:
Use the find command to locate `usermod`:
Linux (Debian/Ubuntu)
find / -name usermod 2>/dev/null
This will search the entire file system for the `usermod` command. The `2>/dev/null` part of the command suppresses any error messages about permission issues during the search.
Once you locate it (e.g., `/usr/sbin/usermod`), use the full path to execute the command:
Linux (Debian/Ubuntu)
/usr/sbin/usermod -aG sudo your_username
Installing `usermod` if Not Found:
If the `usermod` command is not found, you need to install the `passwd` package, which contains `usermod`:
Linux (Debian/Ubuntu)
apt install passwd
Then, you can proceed with adding your user to the `sudo` group:
Linux (Debian/Ubuntu)
usermod -aG sudo your_username
After installation, retry the `usermod` command.
`usermod`: This command modifies a user account.
`-a` (append): This option appends the specified groups to the user's current list of supplementary groups. Without this option, using `-G` would replace all of the user's current supplementary group memberships with the new groups listed.
`-G` (groups): This option specifies the supplementary groups to which the user should be added.
`sudo`: This is the name of the group to which the user will be added. Members of the `sudo` group are granted `sudo` privileges.
`your_username`: Replace this with the actual username of the user you want to add to the `sudo` group.
By completing Step 6, you grant your user the ability to execute commands with superuser privileges using `sudo` on your Linux system.
If you prefer not to use the full path every time, you can temporarily update your PATH to include `/usr/sbin`:
Linux (Debian/Ubuntu)
export PATH=$PATH:/usr/sbin
This step is optional but can be useful if you encounter issues with commands not being found.
Log out and log back in for the group changes to take effect, or use the following command to start a new shell session as the user:
Linux (Debian/Ubuntu)
su - your_username
Then, test your `sudo` privileges by running a simple command:
Linux (Debian/Ubuntu)
sudo ls /root
If you are prompted for a password and the command executes without error, your configuration is successful.
By following these steps, you have installed and configured `sudo` on your Linux system, granting your user the ability to execute commands with superuser privileges. Always use `sudo` carefully to avoid making system-wide changes unintentionally.
Published: June 22, 2024
Have a question or suggestion? Want to request a tutorial or simply leave me a message? I'd love to hear from you! Join our community on Discord for exclusive content, engaging discussions, and more. Thank you! 🌟