Forrest logo
back to the unshare tool

unshare:tldr:cc02f

unshare: Execute a command as a child process without sharing mounts, processes, or networks.
$ unshare --mount --pid --net --fork ${command} ${command_arguments}
try on your machine

The unshare command is used to create a new namespace and run a command within that namespace. The provided command allows you to run a specified command and its associated arguments inside the new isolated namespace.

Let's break down the options used in this particular unshare command:

  • --mount: This option creates a new mount namespace, isolating the filesystem mounts and their related aspects. Processes running within this namespace will have their own separate mount points and won't see mounts from the original namespace or other isolated namespaces.

  • --pid: This option creates a new PID (Process ID) namespace. Processes running in this namespace will have their own process hierarchy, with different process IDs and visibility to processes in other namespaces.

  • --net: This option creates a new network namespace. Processes within this namespace will have their own network stack, network interfaces, routing tables, and firewall rules. They won't be able to communicate directly with processes outside their namespace unless explicitly configured.

  • --fork: This option tells unshare to fork the current process before running the specified command inside the new namespace. This allows the command to execute independently while the original process continues its execution.

${command}: This refers to the specific command you want to execute inside the new namespace. Replace ${command} with your desired command, such as ls, bash, or any other executable you would like to run.

${command_arguments}: These are the optional arguments that you can pass to the specified command. Replace ${command_arguments} with the specific arguments required by the ${command} you are using.

By using the unshare command with the provided options and variables, you create a new isolated environment with separate filesystem, process hierarchy, and network configuration, and execute the specified command within that environment.

This explanation was created by an AI. In most cases those are correct. But please always be careful and never run a command you are not sure if it is safe.
back to the unshare tool