]> git.ipfire.org Git - thirdparty/util-linux.git/blame - sys-utils/unshare.1
Provide better cross references for namespace concepts
[thirdparty/util-linux.git] / sys-utils / unshare.1
CommitLineData
de0f3763 1.TH UNSHARE 1 "February 2016" "util-linux" "User Commands"
4205f1fd 2.SH NAME
ef6acdb8 3unshare \- run program with some namespaces unshared from parent
4205f1fd
MG
4.SH SYNOPSIS
5.B unshare
cf8e0bae 6[options]
dde08a87 7.I program
4205f1fd
MG
8.RI [ arguments ]
9.SH DESCRIPTION
dde08a87 10Unshares the indicated namespaces from the parent process and then executes
0490a6ca
KZ
11the specified \fIprogram\fR.
12.PP
de0f3763
BS
13The namespaces can optionally be made persistent by bind mounting
14/proc/\fIpid\fR/ns/\fItype\fR files to a filesystem path and entered with
15.BR \%nsenter (1)
16even after the \fIprogram\fR terminates.
17Once a persistent \%namespace is no longer needed, it can be unpersisted with
0490a6ca 18.BR umount (8).
de0f3763 19See the \fBEXAMPLES\fR section for more details.
0490a6ca
KZ
20.PP
21The namespaces to be unshared are indicated via options. Unshareable namespaces are:
4205f1fd
MG
22.TP
23.BR "mount namespace"
f85b9777
MK
24Mounting and unmounting filesystems will not affect the rest of the system,
25except for filesystems which are explicitly marked as
f0f22e9c
KZ
26shared (with \fBmount --make-shared\fP; see \fI/proc/self/mountinfo\fP or
27\fBfindmnt -o+PROPAGATION\fP for the \fBshared\fP flags).
f85b9777
MK
28For further details, see
29.BR mount_namespaces (7)
30and the discussion of the
31.BR CLONE_NEWNS
32flag in
33.BR clone (2).
cf8e0bae 34.sp
f0f22e9c
KZ
35.B unshare
36since util-linux version 2.27 automatically sets propagation to \fBprivate\fP
de0f3763
BS
37in a new mount namespace to make sure that the new namespace is really
38unshared. It's possible to disable this feature with option
39\fB\-\-propagation unchanged\fP.
f0f22e9c 40Note that \fBprivate\fP is the kernel default.
4205f1fd
MG
41.TP
42.BR "UTS namespace"
dde08a87 43Setting hostname or domainname will not affect the rest of the system.
f85b9777
MK
44For further details, see
45.BR namespaces (7)
46and the discussion of the
47.BR CLONE_NEWUTS
48flag in
49.BR clone (2).
4205f1fd
MG
50.TP
51.BR "IPC namespace"
de0f3763 52The process will have an independent namespace for System V \%message queues,
f85b9777
MK
53semaphore sets and shared memory segments.
54For further details, see
55.BR namespaces (7)
56and the discussion of the
57.BR CLONE_NEWIPC
58flag in
59.BR clone (2).
4205f1fd
MG
60.TP
61.BR "network namespace"
dde08a87
BS
62The process will have independent IPv4 and IPv6 stacks, IP routing tables,
63firewall rules, the \fI/proc/net\fP and \fI/sys/class/net\fP directory trees,
f85b9777
MK
64sockets, etc.
65For further details, see
66.BR namespaces (7)
67and the discussion of the
68.BR CLONE_NEWNET
69flag in
70.BR clone (2).
4205f1fd 71.TP
bc7f9b95 72.BR "pid namespace"
de0f3763 73Children will have a distinct set of PID-to-process mappings from their parent.
f85b9777
MK
74For further details, see
75.BR pid_namespaces (7)
76and
77the discussion of the
78.BR CLONE_NEWPID
79flag in
80.BR clone (2).
bc7f9b95 81.TP
f9e7b66d
SH
82.BR "cgroup namespace"
83The process will have a virtualized view of \fI/proc\:/self\:/cgroup\fP, and new
84cgroup mounts will be rooted at the namespace cgroup root.
f85b9777
MK
85For further details, see
86.BR cgroup_namespaces (7)
87and the discussion of the
88.BR CLONE_NEWCGROUP
89flag in
90.BR clone (2).
f9e7b66d 91.TP
bc7f9b95 92.BR "user namespace"
dde08a87 93The process will have a distinct set of UIDs, GIDs and capabilities.
f85b9777
MK
94For further details, see
95.BR user_namespaces (7)
96and the discussion of the
97.BR CLONE_NEWUSER
98flag in
99.BR clone (2).
4205f1fd
MG
100.SH OPTIONS
101.TP
de0f3763
BS
102.BR \-i , " \-\-ipc" [ =\fIfile ]
103Unshare the IPC namespace. If \fIfile\fP is specified, then a persistent
104namespace is created by a bind mount.
dde08a87 105.TP
de0f3763
BS
106.BR \-m , " \-\-mount" [ =\fIfile ]
107Unshare the mount namespace. If \fIfile\fP is specified, then a persistent
108namespace is created by a bind mount.
109Note that \fIfile\fP has to be located on a filesystem with the propagation
110flag set to \fBprivate\fP. Use the command \fBfindmnt -o+PROPAGATION\fP
111when not sure about the current setting. See also the examples below.
4205f1fd 112.TP
de0f3763
BS
113.BR \-n , " \-\-net" [ =\fIfile ]
114Unshare the network namespace. If \fIfile\fP is specified, then a persistent
115namespace is created by a bind mount.
bc7f9b95 116.TP
de0f3763
BS
117.BR \-p , " \-\-pid" [ =\fIfile ]
118Unshare the PID namespace. If \fIfile\fP is specified then persistent
119namespace is created by a bind mount. See also the \fB--fork\fP and
120\fB--mount-proc\fP options.
bc7f9b95 121.TP
de0f3763
BS
122.BR \-u , " \-\-uts" [ =\fIfile ]
123Unshare the UTS namespace. If \fIfile\fP is specified, then a persistent
124namespace is created by a bind mount.
dde08a87 125.TP
de0f3763
BS
126.BR \-U , " \-\-user" [ =\fIfile ]
127Unshare the user namespace. If \fIfile\fP is specified, then a persistent
128namespace is created by a bind mount.
5088ec33 129.TP
f9e7b66d
SH
130.BR \-C , " \-\-cgroup"[=\fIfile\fP]
131Unshare the cgroup namespace. If \fIfile\fP is specified then persistent namespace is created
132by bind mount.
133.TP
5088ec33 134.BR \-f , " \-\-fork"
87ec43b6 135Fork the specified \fIprogram\fR as a child process of \fBunshare\fR rather than
de0f3763 136running it directly. This is useful when creating a new PID namespace.
6728ca10 137.TP
de0f3763 138.BR \-\-mount\-proc [ =\fImountpoint ]
cf8e0bae 139Just before running the program, mount the proc filesystem at \fImountpoint\fP
de0f3763 140(default is /proc). This is useful when creating a new PID namespace. It also
6728ca10 141implies creating a new mount namespace since the /proc mount would otherwise
cf8e0bae 142mess up existing programs on the system. The new proc filesystem is explicitly
de0f3763 143mounted as private (with MS_PRIVATE|MS_REC).
4da21e37 144.TP
b06c1ca6 145.BR \-r , " \-\-map\-root\-user"
cf8e0bae
BS
146Run the program only after the current effective user and group IDs have been mapped to
147the superuser UID and GID in the newly created user namespace. This makes it possible to
148conveniently gain capabilities needed to manage various aspects of the newly created
149namespaces (such as configuring interfaces in the network namespace or mounting filesystems in
150the mount namespace) even when run unprivileged. As a mere convenience feature, it does not support
4da21e37 151more sophisticated use cases, such as mapping multiple ranges of UIDs and GIDs.
de0f3763 152This option implies \fB--setgroups=deny\fR.
fbceefde 153.TP
de0f3763
BS
154.BR "\-\-propagation private" | shared | slave | unchanged
155Recursively set the mount propagation flag in the new mount namespace. The default
156is to set the propagation to \fIprivate\fP. It is possible to disable this feature
157with the argument \fBunchanged\fR. The option is silently ignored when the mount
158namespace (\fB\-\-mount\fP) is not requested.
f0f22e9c 159.TP
de0f3763
BS
160.BR "\-\-setgroups allow" | deny
161Allow or deny the
fbceefde 162.BR setgroups (2)
afaf3103
BS
163syscall in a user namespace.
164.sp
165To be able to call
166.BR setgroups (2),
167the calling process must at least have CAP_SETGID.
168But since Linux 3.19 a further restriction applies:
169the kernel gives permission to call
170.BR \%setgroups (2)
171only after the GID map (\fB/proc/\fIpid\fB/gid_map\fR) has been set.
172The GID map is writable by root when
173.BR \%setgroups (2)
174is enabled (i.e. \fBallow\fR, the default), and
175the GID map becomes writable by unprivileged processes when
176.BR \%setgroups (2)
177is permanently disabled (with \fBdeny\fR).
5e43af7e
BS
178.TP
179.BR \-V , " \-\-version"
180Display version information and exit.
181.TP
182.BR \-h , " \-\-help"
183Display help text and exit.
69a7761b
LR
184.SH EXAMPLES
185.TP
186.B # unshare --fork --pid --mount-proc readlink /proc/self
187.TQ
1881
189.br
de0f3763 190Establish a PID namespace, ensure we're PID 1 in it against a newly mounted
69a7761b
LR
191procfs instance.
192.TP
193.B $ unshare --map-root-user --user sh -c whoami
194.TQ
195root
196.br
197Establish a user namespace as an unprivileged user with a root user within it.
0490a6ca 198.TP
0490a6ca
KZ
199.B # touch /root/uts-ns
200.TQ
100a3ab5 201.B # unshare --uts=/root/uts-ns hostname FOO
0490a6ca
KZ
202.TQ
203.B # nsenter --uts=/root/uts-ns hostname
204.TQ
205FOO
206.TQ
207.B # umount /root/uts-ns
208.br
de0f3763
BS
209Establish a persistent UTS namespace, and modify the hostname. The namespace
210is then entered with \fBnsenter\fR. The namespace is destroyed by unmounting
211the bind reference.
249fc8fe 212.TP
249fc8fe
KZ
213.B # mount --bind /root/namespaces /root/namespaces
214.TQ
de0f3763 215.B # mount --make-private /root/namespaces
249fc8fe 216.TQ
de0f3763 217.B # touch /root/namespaces/mnt
249fc8fe 218.TQ
99b3fb9e 219.B # unshare --mount=/root/namespaces/mnt
249fc8fe
KZ
220.br
221Establish a persistent mount namespace referenced by the bind mount
de0f3763
BS
222/root/namespaces/mnt. This example shows a portable solution, because it
223makes sure that the bind mount is created on a shared filesystem.
249fc8fe 224
4205f1fd 225.SH SEE ALSO
c07f86e7 226.BR clone (2),
f053ff1e 227.BR unshare (2),
4a3f0735 228.BR namespaces (7),
c07f86e7 229.BR mount (8)
0490a6ca
KZ
230.SH AUTHORS
231.UR dottedmag@dottedmag.net
232Mikhail Gusarov
233.UE
234.br
235.UR kzak@redhat.com
236Karel Zak
237.UE
4205f1fd 238.SH AVAILABILITY
601d12fb
KZ
239The unshare command is part of the util-linux package and is available from
240ftp://ftp.kernel.org/pub/linux/utils/util-linux/.