Short answer

Your user may not open Docker’s socket, which belongs to root and the docker group. Run sudo usermod -aG docker $USER, then log out and log in again: the group counts only from a new login. Docker 29 words the error “…connect to the docker API at unix:///var/run/docker.sock”; older releases said “…the Docker daemon socket”. Do not chmod 666 the socket.

Tested on Ubuntu 26.04 and 24.04, two separate runs. On 24.04, every step is the same. Everything that differed

The error

Right after installing Docker (install Docker on Ubuntu), any docker command without sudo, as a normal sudo user, gives:

Server
$ docker pspermission denied while trying to connect to the docker API at unix:///var/run/docker.sock
Output hidden (1 line)

The docker command does not run containers itself. It sends requests to the Docker engine over a socket file, /var/run/docker.sock. “Permission denied” means the file system refused to let your user open that file. It is not about the engine, your image or your files.

Why it happens

Server
$ ls -l /var/run/docker.socksrw-rw---- 1 root docker 0 Nov 18 23:04 /var/run/docker.sock
Output hidden (1 line)

s is a socket, rw-rw---- lets the owner (root) and the group (docker) in, and nobody else. Your user is in sudo, not in docker:

Server
$ iduid=1000(deploy) gid=1000(deploy) groups=1000(deploy),27(sudo),100(users)
Output hidden (1 line)

With sudo the command runs as root, so it gets in. That also proves the engine is fine and only access is missing:

Server
$ sudo docker psCONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES
Output hidden (1 line)

The fix: join the docker group, then log in again

Add your user to the group. -a adds it to the groups you have; without it, -G would replace them. In the test, docker ps ran right after it, in the same login:

Server
$ sudo usermod -aG docker $USER$ docker pspermission denied while trying to connect to the docker API at unix:///var/run/docker.sock
Output hidden (1 line)

Still refused, and this is why so many people think the fix failed. Linux gives a process its groups when you log in, so your open session does not have the new group yet. Log out (exit), connect again over SSH, and check:

Server
$ id -nGdeploy sudo users docker
Output hidden (1 line)
Server
$ docker psCONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES
Output hidden (1 line)

docker is in the list and the command works without sudo. A real container to be sure:

Server
$ docker run --rm hello-world[… 19 lines not shown …]To try something more ambitious, you can run an Ubuntu container with: $ docker run -it ubuntu bash Share images, automate workflows, and more with a free Docker ID: https://hub.docker.com/ For more examples and ideas, visit: https://docs.docker.com/get-started/
Output hidden (9 lines)

What the docker group really gives

The engine runs as root and does what a docker-group user asks, including mounting any folder of the server into a container. The test user cannot read root’s home folder:

Server
$ ls -la /rootls: cannot open directory '/root': Permission denied
Output hidden (1 line)

Through docker, with no sudo and no password, it can:

Server
$ docker run --rm -v /root:/host-root alpine ls -la /host-root[… 7 lines not shown …]total 24drwx------    4 root     root          4096 Nov 18 23:03 .drwxr-xr-x    1 root     root          4096 Nov 18 23:05 ..-rw-r--r--    1 root     root          3106 Apr 20  2026 .bashrcdrwx------    2 root     root          4096 Nov 18 23:03 .cache-rw-r--r--    1 root     root           132 Apr 20  2026 .profiledrwx------    2 root     root          4096 Nov 18 23:03 .ssh
Output hidden (8 lines)

The same works for /etc or any other folder, for writing as well as reading. So treat the docker group like the sudo group. On a server shared with people you do not trust that far, look at Docker’s rootless mode instead, where each user runs their own engine without root.

Why not chmod 666 on docker.sock

Many answers online give sudo chmod 666 /var/run/docker.sock. It makes the error go away, for everyone. The test server had a second, ordinary user, intern, in no special group. Before the change:

Server
$ sudo -u intern docker pspermission denied while trying to connect to the docker API at unix:///var/run/docker.sock
Output hidden (1 line)
Server
$ sudo chmod 666 /var/run/docker.sock
Server
$ ls -l /var/run/docker.socksrw-rw-rw- 1 root docker 0 Nov 18 23:04 /var/run/docker.sock
Output hidden (1 line)
Server
$ sudo -u intern docker psCONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES
Output hidden (1 line)

intern is now in, with root’s power through Docker, as is any web app or script that is ever broken into. And it does not even last. systemd makes the socket again with 0660 every time Docker starts. After a reboot:

Server
$ ls -l /var/run/docker.socksrw-rw---- 1 root docker 0 Nov 18 23:05 /var/run/docker.sock
Output hidden (1 line)

Back to srw-rw----, and the error is back for anyone outside the group. The group is the fix that is both deliberate and permanent.

“Cannot connect to the Docker daemon. Is the docker daemon running?”

This looks similar but has a different cause: nothing is answering on the socket, because Docker is stopped. In the test Docker was stopped on purpose (sudo systemctl stop docker.socket docker.service):

Server
$ docker psCannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
Output hidden (1 line)

Group changes do not help here. Start it, and check systemctl status docker if it will not start:

Server
$ sudo systemctl start docker
Server
$ docker psCONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES
Output hidden (1 line)

What the fix changed on the server

Both runs recorded the server before the first step and after the last (see the Tested on box below): only the group files changed (/etc/group, /etc/gshadow and their backups), because usermod added you to the docker group. No package, service, open port or other file in /etc changed: the chmod 666 was gone after the reboot.

Ubuntu 26.04 vs 24.04

The same check ran on a fresh 26.04 server and on a fresh 24.04 server, each with its own run log. Every command printed the same on both, error messages included; only download progress and file dates differed. So this page applies to both as written:

WhatUbuntu 26.04Ubuntu 24.04
SystemUbuntu 26.04.1 LTS7.0.0-43-genericUbuntu 24.04.5 LTS6.8.0-147-generic
docker-ce5:29.10.0-1~ubuntu.26.04~resolute5:29.10.0-1~ubuntu.24.04~noble
docker-ce-cli5:29.10.0-1~ubuntu.26.04~resolute5:29.10.0-1~ubuntu.24.04~noble
containerd.io2.4.2-4~ubuntu.26.04~resolute2.4.2-4~ubuntu.24.04~noble
Commands and resultsThe same on every release: the same commands, the same results.
ProofRun log, 23 checks passedRun log, 23 checks passed

Undo: take a user out of the docker group

Server
$ sudo gpasswd -d $USER dockerRemoving user deploy from group docker
Output hidden (1 line)

Like adding, it counts from the next login. After logging in again the error is back, and sudo docker still works:

Server
$ docker pspermission denied while trying to connect to the docker API at unix:///var/run/docker.sock
Output hidden (1 line)