Are you struggling to run Docker containers without root privileges? To do so, it’s important for you to learn how to add your user to a Docker group on Linux.
Let’s start the process!
How to Add the Current User to a Docker Group?
For adding the current user to the Docker group on Linux:
Step 1: Check for Existing Docker Group (Optional)
Firstly, verify the docker group already exists on the Ubuntu 24.04 system:
cat /etc/group | grep docker
Or run:
grep docker /etc/group
Note: The group already exists if the command outputs a line with docker. Skip to step 2.
Step 2: Create the Docker Group (if needed)
If the group doesn’t exist, use sudo to create a docker group as below:
sudo groupadd docker
Step 3: Add User to Docker Group
Next, add your user to the Docker group with this usermod command:
sudo usermod -aG docker $USER
Here, the -a option tells usermod to append the group (not replace existing ones). Meanwhile, -G specifies the group to add:
Step 4: Refresh Group Membership (Choose One)
Now, log out and log back in for the modifications to take effect.
In contrast, run the newgrp command to switch to the docker group in the current session (it doesn’t persist after closing the terminal):
newgrp docker
Step 5: Verify the Changes
Finally, try running a Docker command without sudo by running a simple test:
docker run hello-world
In this way, you can add the current user to the Docker group using the “sudo usermod -aG docker $USER” command in the Ubuntu 24.04 terminal.
I am a passionate Linux expert with over 3+ years of experience in a wide range of distributions, including Ubuntu, CentOS, Arch Linux, Linux Mint, Debian, Fedora, and more. I love helping others learn Linux by writing clear guides that solve problems and teach new skills.