How to install sudo on Debian or Ubuntu Linux

Whether you are using Debian 11 Bullseye, 10 Buster, Ubuntu 20.04, 18.04, 22.04, or any other minimal server version of the same base, here are there steps to install sudo Debian Linux.

The command sudo, we used before other program calls to execute them. The key purpose of it is to authorize the users to run the program on behalf of and with the rights of another user to perform tasks that are reserved for administrators.

When we run the command with sudo, it asks for the password of the current user before executing the program. This checks whether the user that entered the command is the group of authorized users defined in the /etc/sudoers file or not. The target user is root assumed by default.

Under Debian, in /etc/sudoers all members of the group are sudo and allowed by default to become the user root and thus to receive root rights. The user or users created during installation belong to the group sudo by default.

In GUI desktop environments such as GNOME or KDE, root rights are sometimes automatically requested for a certain program for certain tasks by giving a graphical dialogue box. For example, you are automatically asked for your password for a program installation or upgrading system graphically, so that APT receives root rights and can install the program. In many cases, sudo no longer needs to be called manually.

Easy way to understand what sudo is for-

What is sudo in Linux

Command to Install sudo on Debian Linux Minimal server

Well, sudo is already in the Debian system most of the time; however, in minimal Debian installation such as Debian on Docker, the sudo will be missing. Hence, to create any other user and use that to install some software without giving root access for all the commands, we have to install sudo manually using the command line. Here are the steps to follow.

This article assumes that you already have root user access because without that we cannot install “sudo” or any other packages.

1. Apt update cache

First, run the system update command to refresh the APT repositories cache. This is necessary because many times after installing a fresh minimal Debian or Ubuntu Linux, it won’t recognize any packages to install. It is because there is no list of packages in the cache, that the system can identify to install.

apt update && apt upgrade

 

2. Command to install sudo on Debian or Ubuntu server

You have the updated minimal Debian or Ubuntu server, now we can easily use the APT package manager command to install the “sudo” without the help of any additional repository as it is already available in the base repo of Debian.

apt install sudo

command to install sudo debian

 

3. Create a new user

Once the sudo is installed, let’s create a new user to use later with the sudo command.

adduser your-new-user

Change “your-new-user” with whatever name you want to give to your user.

For example, here we area adding a user called – h2smedia, the command will be like this:

adduser h2smedia

Set password when it asks.

Add new user

 

4. Add a new user to the sudo group in Debian

This is an important step otherwise you won’t be able to use your new user with sudo rights to install new programs.

usermod -aG sudo h2smedia

Again replace h2smedia with your user created above.

Add user to sudo group in Debian 11

 

5. Switch to new user

Now, let’s switch to the newly created user from root to run a non-root user but with sudo rights.

su your-new-user

Run sudo commands, to test it:

sudo apt update

Enter the password you have created for your user.

Add user to sudo group in Debian 11

Now to log back again to the root user, you can simply type:

sudo su -

 

Conclusion:

In this way, anybody who has the root user rights can install and add a new user with sudo rights. However, make sure you are using a strong password.

 

Other Articles:

2 Ways to add users to a sudoers group in Debian 11
How to download and install CentOS 8 minimal server 
Install Plex Media Server on Debian 11 Bullseye

 

2 thoughts on “How to install sudo on Debian or Ubuntu Linux”

  1. I have Ubuntu 18.04 but cannot do the following install:
    /home/fred/Downloads/hotspot shield)f=hotspotshield_1.0.7_amd64.deb

    /home/fred/Downloads/hotspot shield)sudo apt install ./$f
    Reading package lists… Done
    Building dependency tree
    Reading state information… Done
    Note, selecting ‘hotspotshield:amd64’ instead of ‘./hotspotshield_1.0.7_amd64.deb’
    Some packages could not be installed. This may mean that you have
    requested an impossible situation or if you are using the unstable
    distribution that some required packages have not yet been created
    or been moved out of Incoming.
    The following information may help to resolve the situation:

    The following packages have unmet dependencies:
    hotspotshield:amd64 : Depends: libdbus-1-3:amd64 (>= 1.10) but it is not installable
    Depends: libnl-3-200:amd64 (>= 3.2.0) but it is not installable
    Depends: libnl-route-3-200:amd64 (>= 3.2.0) but it is not installable
    Depends: network-manager:amd64 (>= 1.10) but it is not installable
    E: Unable to correct problems, you have held broken packages.

    How can I fix this?

    Reply

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.