Skip to the workspace
Pebellslearn by building
Underlying Technologies  ›  Lesson

Users, Groups and Permissions

Users / Groups Permissions 14 minLinux decides access by numeric user and group IDs and three sets of read, write and execute bits, and containers run as root unless the image or command chooses another user.

docker / Users, Groups and Permissions

Explore each scene at your own pace.

01 · The rule

The rule

Users, Groups and Permissions

You start quicknotes in a container and run whoami inside it. The answer is root. That surprises most people, and it matters: if someone finds a hole in quicknotes, they get whatever power that user has. Understanding Linux users and permissions lets you fix it.

The rule

Containers run as root unless you say otherwise — so say otherwise.

Linux identifies every user by a number, the UID, and every group by a GID. Names like root or app are just labels looked up in /etc/passwd; the kernel only cares about the numbers. root is always UID 0 and may do almost anything.

Every file has an owner, a group, and three sets of permission bits. ls -l shows them:

$ ls -l /app
-rw-r--r-- 1 root root  812 app.py
-rwxr-x--- 1 app  app   143 start.sh

After the first character (- for a file, d for a directory) come three triplets of read, write and execute: for the owner, the group, and others. As numbers, r = 4, w = 2, x = 1, added per triplet, so rwxr-x--- is 750. You change them with chmod and change the owner with chown.

In a Dockerfile you create an ordinary user and switch to it before the app starts:

RUN useradd --create-home app
USER app
CMD ["python", "app.py"]

From USER app onward, later instructions and the running container use that user instead of root.

Scene 1 of 5
Hover to wake the cannons. Drag to move, or use arrow keys when focused. Press Enter to fire a shot.