usermod -aG docker $USER stops the sudo prompt. It also grants root-equivalent access to the machine, which is a fair trade on your laptop and a poor one on a shared server.
The permission denied error on /var/run/docker.sock sends everyone to the same three commands, and they work. What almost nobody mentions is what the fix actually grants.
Membership of the docker group is not “permission to use Docker”. It is unrestricted access to the daemon, and the daemon runs as root.
Table of contents
- The commands
- What you just granted
- When it is fine and when it is not
- Rootless Docker, the actual alternative
- Narrower options when the group is too much
- Not having the problem
- How this fits the rest of the stack
- FAQ
The commands
# The group usually exists already after installing Docker
sudo groupadd docker
# Add yourself
sudo usermod -aG docker $USER
# Pick up the new group membership
newgrp docker # this shell only
# or log out and back in for every session
# Verify
docker run --rm hello-world
-aG matters: -a means append. usermod -G docker $USER without it replaces your entire group list, which will remove you from sudo, wheel, and anything else you belong to. That is a genuinely bad afternoon and the most common mistake here.
The other regular confusion: group membership is established at login. Running usermod does not affect your current shell, so docker ps still fails until you use newgrp or log out and back in. Over SSH, a fresh connection is required — and id -nG shows what your current session actually has.
What you just granted
The docker group grants write access to the Docker socket. Anyone who can write to that socket can start a container, and starting a container includes this:
docker run -v /:/host -it alpine chroot /host sh
That mounts the host’s entire filesystem into a container and gives you a root shell on it. No exploit, no vulnerability — it is the documented behaviour of a tool doing exactly what it was asked.
So docker group membership is equivalent to passwordless root, and Docker’s own documentation says so. The practical consequences:
- Adding a user to the docker group makes them a full administrator, whatever your sudoers file says.
- Any process running as that user can do the same — including a compromised dependency in a build script.
- It bypasses sudo logging, so the audit trail shows a container start rather than a privilege escalation.
None of this makes the group wrong to use. It makes it a decision to take deliberately rather than by following a Stack Overflow answer.
When it is fine and when it is not
Reasonable: your own development machine, where you already have sudo and are the only user. The group changes convenience, not your actual authority.
Reasonable: a dedicated CI runner that is already isolated and rebuilt regularly, where the build has to produce images anyway.
Not reasonable: a shared server with multiple users, where it silently promotes everyone in the group to administrator. A production host where the deploy user should have narrow permissions. Any environment with an audit requirement, since the escalation path is invisible.
The test worth applying: would you give this user unrestricted sudo with no password? If not, do not add them to the docker group, because you have done the same thing with less visibility.
Rootless Docker, the actual alternative
Rootless mode runs the entire daemon as your user, using user namespaces. No root daemon, no root-equivalent group.
# Install the rootless setup (Docker 20.10+)
dockerd-rootless-setuptool.sh install
# Point the client at your own daemon
export DOCKER_HOST=unix:///run/user/$UID/docker.sock
systemctl --user enable --now docker
sudo loginctl enable-linger $USER # keep it running after logout
The limitations are real but narrower than they used to be:
- Ports below 1024 need
net.ipv4.ip_unprivileged_port_startlowered, or a proxy. - Some storage drivers and network modes are unavailable.
- File ownership in bind mounts follows the UID mapping, the same wrinkle rootless Podman has.
- Slightly lower performance in some filesystem-heavy workloads.
For a development machine, rootless Docker gets you the convenience without the escalation path, and it is the better default in 2026. Podman is rootless by design and worth considering if you are choosing fresh.
Narrower options when the group is too much
If the group is unacceptable and rootless will not work, there are middle grounds.
Scoped sudo rules — specific commands only, and logged:
# /etc/sudoers.d/docker-deploy (edit with visudo)
deploy ALL=(root) NOPASSWD: /usr/bin/docker compose -f /srv/app/compose.yml up -d
deploy ALL=(root) NOPASSWD: /usr/bin/docker compose -f /srv/app/compose.yml pull
This is genuinely narrower than group membership: the user can run those exact invocations and nothing else, and every use is logged. Be careful that the allowed command cannot take arbitrary arguments, or you have reinvented the problem.
A socket proxy that filters the API, exposing only the endpoints a given consumer needs. This is the standard answer for tools that want Docker access — a monitoring agent needs to list containers, not create privileged ones.
Do not loosen permissions on the socket file itself. chmod 666 /var/run/docker.sock appears in old answers and grants every user on the machine root.
Not having the problem
This whole question exists because the machine running containers is the machine people log into. Separating those removes it: developers build and push, and the runtime is somewhere they do not have shell access to at all.
That is the shape of most managed platforms, and it is worth noting that “who can run Docker on the production host” is a question that only has an answer if there is a production host you log into.
On RunxBuild, Docker services build from a connected repository — push code, get a build log, a live route, runtime logs and rollback to a previous deploy. There is no host to add anyone to a group on, and the deploy permission is a dashboard permission rather than a socket.
How this fits the rest of the stack
sudo usermod -aG docker $USER is the answer to the question and grants root-equivalent access as a side effect — fine on your own laptop, wrong on a shared or production host. Prefer rootless Docker where you can, scoped sudo rules where you cannot, and never chmod the socket. Where the runtime is a platform rather than a host you log into, the question stops applying; the RunxBuild hosting calculator shows what a Docker service costs to run there.
Useful related references:
- Add a User to the Docker Group: Running Docker Without sudo (and the Risk)
- Installation of Docker in Ubuntu: Step-by-Step for 22.04 and 24.04
- How to Install Docker on Ubuntu: 2026 Guide (22.04 and 24.04)
- Database user management on RunxBuild
FAQ
How do I run Docker without sudo?
Add your user to the docker group with sudo usermod -aG docker $USER, then run newgrp docker or log out and back in so the membership takes effect. Be aware this grants root-equivalent access to the machine.
Is adding a user to the docker group safe?
It is equivalent to passwordless root, because anyone who can reach the Docker socket can start a container that mounts the host filesystem. Acceptable on your own development machine; not on a shared server, a production host, or anywhere with audit requirements.
Why does docker still say permission denied after usermod?
Group membership is established at login, so your current shell does not have it yet. Run newgrp docker for that shell, or log out and back in. Check with id -nG to see what the session actually has.
What is rootless Docker?
A mode where the daemon runs as your unprivileged user using user namespaces, so there is no root daemon and no root-equivalent group. Install it with dockerd-rootless-setuptool.sh install. Ports below 1024 and some storage drivers are the main limitations.
Can I give someone limited Docker access?
Yes, with scoped sudoers rules allowing specific full commands, or a socket proxy that exposes only the API endpoints a tool needs. Do not chmod the socket to 666 — that grants every user on the machine root.