1 .TH UNSHARE 1 "July 2014" "util-linux" "User Commands"
3 unshare \- run program with some namespaces unshared from parent
10 Unshares the indicated namespaces from the parent process and then executes
11 the specified \fIprogram\fR. The namespaces to be unshared are indicated via
12 options. Unshareable namespaces are:
15 Mounting and unmounting filesystems will not affect the rest of the system
16 (\fBCLONE_NEWNS\fP flag), except for filesystems which are explicitly marked as
17 shared (with \fBmount --make-shared\fP; see \fI/proc/self/mountinfo\fP for the
20 It's recommended to use \fBmount --make-rprivate\fP or \fBmount --make-rslave\fP
21 after \fBunshare --mount\fP to make sure that mountpoints in the new namespace
22 are really unshared from the parental namespace.
25 Setting hostname or domainname will not affect the rest of the system.
26 (\fBCLONE_NEWUTS\fP flag)
29 The process will have an independent namespace for System V message queues,
30 semaphore sets and shared memory segments. (\fBCLONE_NEWIPC\fP flag)
32 .BR "network namespace"
33 The process will have independent IPv4 and IPv6 stacks, IP routing tables,
34 firewall rules, the \fI/proc/net\fP and \fI/sys/class/net\fP directory trees,
35 sockets, etc. (\fBCLONE_NEWNET\fP flag)
38 Children will have a distinct set of PID to process mappings from their parent.
39 (\fBCLONE_NEWPID\fP flag)
42 The process will have a distinct set of UIDs, GIDs and capabilities.
43 (\fBCLONE_NEWUSER\fP flag)
45 See \fBclone\fR(2) for the exact semantics of the flags.
49 Unshare the IPC namespace.
51 .BR \-m , " \-\-mount"
52 Unshare the mount namespace.
55 Unshare the network namespace.
58 Unshare the pid namespace.
59 See also the \fB--fork\fP and \fB--mount-proc\fP options.
62 Unshare the UTS namespace.
65 Unshare the user namespace.
68 Fork the specified \fIprogram\fR as a child process of \fBunshare\fR rather than
69 running it directly. This is useful when creating a new pid namespace.
71 .BR \-\-mount\-proc "[=\fImountpoint\fP]"
72 Just before running the program, mount the proc filesystem at \fImountpoint\fP
73 (default is /proc). This is useful when creating a new pid namespace. It also
74 implies creating a new mount namespace since the /proc mount would otherwise
75 mess up existing programs on the system. The new proc filesystem is explicitly
76 mounted as private (by MS_PRIVATE|MS_REC).
78 .BR \-r , " \-\-map\-root\-user"
79 Run the program only after the current effective user and group IDs have been mapped to
80 the superuser UID and GID in the newly created user namespace. This makes it possible to
81 conveniently gain capabilities needed to manage various aspects of the newly created
82 namespaces (such as configuring interfaces in the network namespace or mounting filesystems in
83 the mount namespace) even when run unprivileged. As a mere convenience feature, it does not support
84 more sophisticated use cases, such as mapping multiple ranges of UIDs and GIDs.
85 This option implies --setgroups=deny.
87 .BR \-s , " \-\-setgroups \fIallow|deny\fP"
90 syscall in user namespaces.
93 is only callable with CAP_SETGID and CAP_SETGID in a user
94 namespace (since Linux 3.19) does not give you permission to call setgroups(2)
95 until after GID map has been set. The GID map is writable by root when
97 is enabled and GID map becomes writable by unprivileged processes when
99 is permanently disabled.
101 .BR \-V , " \-\-version"
102 Display version information and exit.
104 .BR \-h , " \-\-help"
105 Display help text and exit.
108 .B # unshare --fork --pid --mount-proc readlink /proc/self
112 Establish a PID namespace, ensure we're PID 1 in it against newly mounted
115 .B $ unshare --map-root-user --user sh -c whoami
119 Establish a user namespace as an unprivileged user with a root user within it.
127 Mikhail Gusarov <dottedmag@dottedmag.net>
129 The unshare command is part of the util-linux package and is available from
130 ftp://ftp.kernel.org/pub/linux/utils/util-linux/.