Podman’s unshare command lets you enter a user namespace, which is essentially a fresh, isolated environment where your user ID (UID) and group ID (GID) are mapped to different values than they are on the host system.

Let’s see it in action. Imagine you’re troubleshooting a container that’s failing with permission errors when it tries to write to a specific directory.

# On the host, your UID might be 1000
id

# Now, enter a user namespace with 'podman unshare' and run 'id' again
podman unshare bash

# Inside the unshare, your UID will appear as 0
id

# Now, try to create a file in a directory that's normally restricted
# For example, if /mnt/restricted is owned by root on the host
mkdir /mnt/restricted
touch /mnt/restricted/testfile
ls -l /mnt/restricted/testfile

The touch command will succeed inside the unshare, even if /mnt/restricted was read-only or owned by root on the host. This is because, within the user namespace, your UID of 0 (root) is mapped to your host UID of 1000 (your regular user). The directory /mnt/restricted is seen by the process inside the namespace as owned by UID 0, which is you inside the namespace.

This capability directly addresses the problem of containers running with root privileges inside the container but mapping to a non-root user on the host, a common security practice. When debugging issues that involve file permissions or process privileges within a container, especially those related to how the container interacts with the host filesystem or other host resources, podman unshare provides a safe, isolated environment to test these interactions.

Here’s how it works internally: podman unshare leverages Linux kernel features like unshare(2) and clone(2) system calls to create new namespaces for the process. Specifically, it creates a new user namespace, a new mount namespace, and a new PID namespace by default. The user namespace is the key here: it allows the process to have a different view of user and group IDs. When you enter a shell via podman unshare bash, that shell and any commands you run within it operate under these new namespace mappings.

The primary benefit is safe experimentation. You can run commands that would normally require root privileges on the host, or that would fail due to permission restrictions, without actually granting those privileges to your host user or compromising system security. For example, you could test mounting a host directory into a container-like environment or inspecting files that your regular user wouldn’t normally have access to.

Consider debugging a scenario where a container needs to write to a volume mounted from the host. If the host directory has restrictive permissions, the container might fail. By using podman unshare, you can enter a shell where your user ID is effectively 0 (root) within that namespace. Then, you can attempt to write to that mounted directory (which you’d typically do by first creating a container that uses that mount, or by pre-mounting it within the unshare’s mount namespace if you’re doing more advanced testing). This allows you to isolate whether the problem is with the container’s internal permissions, Podman’s volume mounting, or the host’s filesystem permissions.

The command also allows you to specify which namespaces to unshare using flags like --mount, --pid, --net, --ipc, and --uts. For instance, podman unshare --mount bash would create new user and mount namespaces.

When you run podman unshare bash, the bash process is spawned with a new set of namespaces. The user namespace is configured such that UID 0 inside the namespace maps to your current host UID. All subsequent processes forked from this bash process inherit these namespaces. This means that any command you run, like ls or touch, will see the world through the lens of these new namespace mappings.

One critical aspect often overlooked is how these namespaces interact with network operations. By default, podman unshare creates a new network namespace. This means the process inside the unshare will have its own network stack, isolated from the host. If you’re trying to debug network-related issues, this isolation is crucial. However, it also means that services running inside the unshare won’t be directly accessible from the host’s network interfaces unless you explicitly configure network bridging or port forwarding, which is outside the scope of a basic unshare command.

If you encounter "permission denied" errors when trying to access files on the host from within a podman unshare session, even though your UID appears as 0, it’s likely due to the way mount namespaces work. The mount namespace isolates filesystem views. If the directory you’re trying to access wasn’t explicitly mounted or re-mounted within the unshare’s new mount namespace, its permissions and ownership from the host’s perspective will still be enforced, and your mapped UID might not have the necessary access.

The next logical step after successfully debugging permission issues with podman unshare is to understand how to integrate this into actual container workflows, particularly with Podman’s rootless capabilities.

Want structured learning?

Take the full Podman course →