Fix "Permission Denied" Connecting to the Docker Daemon
The daemon socket is owned by root, and your user isn't allowed to touch it. Here's the fix, and why the obvious one is a security smell.
Key takeaways
- The error means your user cannot open /var/run/docker.sock, which only root and the docker group can access.
- Run sudo usermod -aG docker $USER, then newgrp docker or log out and back in.
- Docker's own docs warn the docker group grants root-level privileges, so use rootless mode on shared machines.
On this page
Fix "permission denied while trying to connect to the Docker daemon socket" by adding your user to the docker group with sudo usermod -aG docker $USER, then running newgrp docker or logging back in. The socket is readable only by root and that group. On shared machines, use rootless Docker instead, because the group is root-equivalent.
Verified against
Docker Engine 29.9 (29.9.2, released 2026-10-20), against the docs.docker.com Linux post-installation, rootless mode and daemon troubleshooting pages. Checked October 2026.
This is what it looks like on a fresh box (the API version in the URL varies by client):
$ docker ps
Got permission denied while trying to connect to the Docker daemon socket at
unix:///var/run/docker.sock: Get "http://%2Fvar%2Frun%2Fdocker.sock/v1.xx/containers/json":
dial unix /var/run/docker.sock: connect: permission denied
Nothing is broken. Docker is running fine. Your user account just isn't allowed to talk to it.
What's actually happening
The Docker CLI is a thin client. It sends API calls over a Unix socket to the dockerd daemon, which pulls images and starts containers. That socket lives at /var/run/docker.sock, and the daemon runs as root. Look at who owns it, and at who you are:
$ ls -l /var/run/docker.sock
srw-rw---- 1 root docker 0 Oct 30 09:14 /var/run/docker.sock
$ id -nG
kiril adm sudo users
Owner root, group docker, mode srw-rw----: root and members of docker can read and write, everyone else gets nothing. Your group list has no docker, so you are "everyone else." That's the whole problem.
The standard fix, step by step
These are the commands from Docker's post-install docs. groupadd just reports that the group exists on most package installs:
$ sudo groupadd docker
$ sudo usermod -aG docker $USER
$ newgrp docker
$ docker run hello-world
The -aG matters. -a appends; leave it off and usermod replaces your supplementary groups with just docker, quietly removing you from sudo and adm. People have locked themselves out of a box this way.
Group membership is read at login, so the change does not apply to shells you already have open. newgrp docker starts one new shell with the group; every other terminal, IDE and SSH session needs a logout and login. Verify:
$ id
uid=1000(kiril) gid=1000(kiril) groups=1000(kiril),4(adm),27(sudo),100(users),998(docker)
998(docker) is there, so docker ps now works without sudo. If you have ever run sudo docker, fix the config directory ownership too, using the command from the same docs page:
$ sudo chown "$USER":"$USER" /home/"$USER"/.docker -R
$ sudo chmod g+rwx "$HOME/.docker" -R
The error strings, and what each one means
| Error text | Cause | Fix |
|---|---|---|
permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock | User not in docker group, or session predates the change | usermod -aG docker $USER, then newgrp docker or re-login |
WARNING: Error loading config file: /home/user/.docker/config.json - stat ...: permission denied | Earlier sudo docker left root-owned files in ~/.docker | The chown and chmod commands above |
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running? | Daemon stopped, or DOCKER_HOST points elsewhere | sudo systemctl start docker; unset DOCKER_HOST |
cannot expose privileged port 80, you might need to add "net.ipv4.ip_unprivileged_port_start=0" | Rootless daemon binding a port below 1024 | Publish -p 8080:80, or lower the sysctl |
Failed to connect to bus: No such file or directory | systemctl --user after sudo -iu in rootless setup | Log in via SSH or machinectl shell user@ |
The "Cannot connect" error is a different problem with a similar shape. Here the socket exists but nothing answers, and cannot connect to the Docker daemon walks through that one.
"But sudo docker works fine"
It does, and that's the trap. sudo docker ps sidesteps the permission check because root can open any socket. Plenty of people alias docker to sudo docker and move on.
Two reasons that bites you. Files the CLI creates, like ~/.docker/config.json, end up owned by root, which is exactly the second error in the table. And it hides the real permission model, so the next person on the box has no idea how access is granted. Sudo working is a signal that your user isn't wired up, not a solution.
The part nobody mentions: the docker group is root
Adding yourself to the docker group is, for practical purposes, granting yourself passwordless root. The daemon runs as root, and anyone who can send it API calls can ask it to do root things:
$ docker run -v /:/host -it alpine chroot /host sh
That mounts the host filesystem into a container and drops you into a shell with write access to all of it. No password prompt. From there you can edit /etc/shadow or add a sudoer. Docker's post-install docs say it outright: "The docker group grants root-level privileges to the user."
On your own laptop, fine. On a shared build server, handing out docker-group membership is how you get a privilege-escalation finding in the next audit.
What we'd reach for instead: rootless Docker
Rootless mode runs the whole daemon as your unprivileged user, using user namespaces so that root inside a container maps to your normal UID outside it. A container breakout gets your permissions, not the host's.
The docs list two prerequisites: newuidmap and newgidmap (the uidmap package on most distros), and at least 65,536 subordinate IDs for your user in /etc/subuid and /etc/subgid. Then:
$ grep "^$USER:" /etc/subuid /etc/subgid
/etc/subuid:kiril:231072:65536
/etc/subgid:kiril:231072:65536
$ dockerd-rootless-setuptool.sh install
$ systemctl --user start docker
$ sudo loginctl enable-linger $(whoami)
$ export DOCKER_HOST=unix:///run/user/$(id -u)/docker.sock
$ docker run hello-world
If the system-wide daemon is still running, the docs say to pass --force to the install, or disable it first with sudo systemctl disable --now docker.service docker.socket. enable-linger keeps your daemon running after you log out. If RootlessKit reports No subuid ranges found for user, the /etc/subuid entry is missing.
If rootless doesn't fit, the next-best move is scoped access: give specific service accounts the socket through a controlled path, or front the daemon with something that enforces policy, rather than making every developer effectively root.
The other places this shows up
Docker Desktop (Mac and Windows) runs the engine inside its own VM. Permission denied there usually means the app isn't started, or a stale DOCKER_HOST points at a socket that no longer exists. Unset it and let Desktop manage the context with unset DOCKER_HOST and docker context use desktop-linux.
CI runners. There's no interactive login, so newgrp doesn't apply. The runner's service user must be in the docker group when the agent process starts. If you added the group while the agent was running, restart the agent; it still holds its old group set.
systemd services. A unit runs as its User=, and groups are resolved at start, so run sudo systemctl restart your-service after the group change.
Where this breaks
None of this applies when the socket isn't Docker's default. Podman, Colima, or a remote DOCKER_HOST over SSH each have their own socket path and permission model, so check docker context ls before editing groups. Rootless mode is also not a universal swap: the docs list s390x as unsupported, ports below 1024 need extra configuration, and anything that genuinely needs host-root access (some monitoring agents, --privileged workloads) won't run the same way.
Questions people ask
Why does newgrp docker fix permission denied?
Linux reads your group list when a session starts, so usermod -aG docker $USER changes nothing for shells already open. newgrp docker launches a fresh shell with the docker group active, which lets it open /var/run/docker.sock. It only fixes that one shell. Other terminals, IDEs, and SSH sessions still need a full logout and login before docker ps works without sudo.
I added myself to the docker group and still get permission denied. What now?
Check four things. Run id and confirm docker appears; if not, the session predates the change. Run ls -l /var/run/docker.sock and confirm the group is docker with rw bits. Run echo $DOCKER_HOST and unset it if it points at a dead socket. If the error mentions ~/.docker/config.json, an earlier sudo docker left root-owned files, so chown the directory back to yourself.
Is adding a user to the docker group safe?
Only where that user could have root anyway. Docker's documentation states the group "grants root-level privileges to the user", because anyone who can reach the daemon can mount / into a container and edit it. On a personal workstation that is acceptable. On shared servers and CI hosts, use rootless mode, where the daemon runs as your own UID.
The call we'd make
On your personal machine, add yourself to the docker group and get on with your day; the blast radius is you. On anything shared, build infrastructure, or anywhere an auditor will eventually look, don't. Stand up rootless Docker so a compromised container can't become a compromised host, or hand out scoped socket access to the accounts that need it. For the neighboring errors this one travels with, keep the Docker troubleshooting guide open.
Sources
Cite this article
Kiril Urbonas (2026). Fix "Permission Denied" Connecting to the Docker Daemon. DevOpsNess. Updated 2026-10-31. https://www.devopsness.com/blog/fix-docker-permission-denied
[Fix "Permission Denied" Connecting to the Docker Daemon](https://www.devopsness.com/blog/fix-docker-permission-denied) (Kiril Urbonas, DevOpsNess, updated 2026-10-31)
More from DevOps
Explore more articles in this category
kaniko CVE-2026-105769: Lookalike ACR Hosts Get Your Azure Token. Rebuild on v1.25.20
A FROM line pointing at a host like x.azurecr.io.attacker.com is enough to make kaniko hand the build's Entra ID token to that host. Which kaniko forks and images are affected, how to find Azure identities in your build pods, and what to rotate.
Sign Container Images With Cosign: Keyless GitHub Actions Workflow, SBOM and In-Cluster Checks
One workflow that builds, signs keylessly with GitHub OIDC, attaches an SBOM and SLSA provenance, plus the Kyverno policy that refuses anything unsigned. Copy it, change three names, ship it.
GitLab CVE-2026-110264: A Second CVSS 10 RCE in Nine Days. Patch to 19.5.1
An unauthenticated regex-compiler RCE reaching back to GitLab 7.0, no workaround, and backports on older branches that fix only the critical bug. The exact version per branch and the commands to get there.
You might have missed
Evergreen posts worth revisiting.