]> git.ipfire.org Git - thirdparty/util-linux.git/blame - sys-utils/unshare.1
libsmartcols: fix right-aligned logic for last column
[thirdparty/util-linux.git] / sys-utils / unshare.1
CommitLineData
cf8e0bae 1.TH UNSHARE 1 "July 2014" "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
13The namespaces can optionally be persisted by bind mounting /proc/[pid]/ns/[type] files
14to a filesystem path and entered with
15.BR nsenter (1)
16even after \fIprogram\fR terminates.
17Once a persistent namespace is no longer needed it can be unpersisted with
18.BR umount (8).
19See EXAMPLES section for more details.
20.PP
21The namespaces to be unshared are indicated via options. Unshareable namespaces are:
4205f1fd
MG
22.TP
23.BR "mount namespace"
dde08a87 24Mounting and unmounting filesystems will not affect the rest of the system
bc87f885 25(\fBCLONE_NEWNS\fP flag), except 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).
cf8e0bae 28.sp
f0f22e9c
KZ
29.B unshare
30since util-linux version 2.27 automatically sets propagation to \fBprivate\fP
31in the new mount namespace to make sure that the new namespace is really
32unshared. This feature is possible to disable by option \fB\-\-propagation unchanged\fP.
33Note that \fBprivate\fP is the kernel default.
4205f1fd
MG
34.TP
35.BR "UTS namespace"
dde08a87
BS
36Setting hostname or domainname will not affect the rest of the system.
37(\fBCLONE_NEWUTS\fP flag)
4205f1fd
MG
38.TP
39.BR "IPC namespace"
dde08a87
BS
40The process will have an independent namespace for System V message queues,
41semaphore sets and shared memory segments. (\fBCLONE_NEWIPC\fP flag)
4205f1fd
MG
42.TP
43.BR "network namespace"
dde08a87
BS
44The process will have independent IPv4 and IPv6 stacks, IP routing tables,
45firewall rules, the \fI/proc/net\fP and \fI/sys/class/net\fP directory trees,
46sockets, etc. (\fBCLONE_NEWNET\fP flag)
4205f1fd 47.TP
bc7f9b95 48.BR "pid namespace"
dde08a87
BS
49Children will have a distinct set of PID to process mappings from their parent.
50(\fBCLONE_NEWPID\fP flag)
bc7f9b95
EB
51.TP
52.BR "user namespace"
dde08a87
BS
53The process will have a distinct set of UIDs, GIDs and capabilities.
54(\fBCLONE_NEWUSER\fP flag)
e41e0f95 55.PP
dde08a87 56See \fBclone\fR(2) for the exact semantics of the flags.
4205f1fd
MG
57.SH OPTIONS
58.TP
0490a6ca
KZ
59.BR \-i , " \-\-ipc"[=\fIfile\fP]
60Unshare the IPC namespace. If \fIfile\fP is specified then persistent namespace is created
61by bind mount.
dde08a87 62.TP
0490a6ca
KZ
63.BR \-m , " \-\-mount"[=\fIfile\fP]
64Unshare the mount namespace. If \fIfile\fP is specified then persistent namespace is created
65by bind mount.
4205f1fd 66.TP
0490a6ca
KZ
67.BR \-n , " \-\-net"[=\fIfile\fP]
68Unshare the network namespace. If \fIfile\fP is specified then persistent namespace is created
69by bind mount.
bc7f9b95 70.TP
0490a6ca
KZ
71.BR \-p , " \-\-pid"[=\fIfile\fP]
72Unshare the pid namespace. If \fIfile\fP is specified then persistent namespace is created
73by bind mount. See also the \fB--fork\fP and \fB--mount-proc\fP options.
bc7f9b95 74.TP
0490a6ca
KZ
75.BR \-u , " \-\-uts"[=\fIfile\fP]
76Unshare the UTS namespace. If \fIfile\fP is specified then persistent namespace is created
77by bind mount.
dde08a87 78.TP
0490a6ca
KZ
79.BR \-U , " \-\-user"[=\fIfile\fP]
80Unshare the user namespace. If \fIfile\fP is specified then persistent namespace is created
81by bind mount.
5088ec33
MF
82.TP
83.BR \-f , " \-\-fork"
87ec43b6
BS
84Fork the specified \fIprogram\fR as a child process of \fBunshare\fR rather than
85running it directly. This is useful when creating a new pid namespace.
6728ca10 86.TP
b06c1ca6 87.BR \-\-mount\-proc "[=\fImountpoint\fP]"
cf8e0bae 88Just before running the program, mount the proc filesystem at \fImountpoint\fP
6728ca10
KZ
89(default is /proc). This is useful when creating a new pid namespace. It also
90implies creating a new mount namespace since the /proc mount would otherwise
cf8e0bae 91mess up existing programs on the system. The new proc filesystem is explicitly
c07f86e7 92mounted as private (by MS_PRIVATE|MS_REC).
4da21e37 93.TP
b06c1ca6 94.BR \-r , " \-\-map\-root\-user"
cf8e0bae
BS
95Run the program only after the current effective user and group IDs have been mapped to
96the superuser UID and GID in the newly created user namespace. This makes it possible to
97conveniently gain capabilities needed to manage various aspects of the newly created
98namespaces (such as configuring interfaces in the network namespace or mounting filesystems in
99the mount namespace) even when run unprivileged. As a mere convenience feature, it does not support
4da21e37 100more sophisticated use cases, such as mapping multiple ranges of UIDs and GIDs.
fbceefde
KZ
101This option implies --setgroups=deny.
102.TP
f0f22e9c
KZ
103.BR "\-\-propagation \fIprivate|shared|slave|unchanged\fP"
104Recursively sets mount propagation flag in the new mount namespace. The default
105is to set the propagation to \fIprivate\fP, this feature is possible to disable
106by \fIunchanged\fP argument. The options is silently ignored when mount namespace (\fB\-\-mount\fP)
107is not requested.
108.TP
109.BR "\-\-setgroups \fIallow|deny\fP"
fbceefde
KZ
110Allow or deny
111.BR setgroups (2)
112syscall in user namespaces.
113
114.BR setgroups(2)
115is only callable with CAP_SETGID and CAP_SETGID in a user
116namespace (since Linux 3.19) does not give you permission to call setgroups(2)
117until after GID map has been set. The GID map is writable by root when
118.BR setgroups(2)
119is enabled and GID map becomes writable by unprivileged processes when
120.BR setgroups(2)
a55f60a1 121is permanently disabled.
5e43af7e
BS
122.TP
123.BR \-V , " \-\-version"
124Display version information and exit.
125.TP
126.BR \-h , " \-\-help"
127Display help text and exit.
69a7761b
LR
128.SH EXAMPLES
129.TP
130.B # unshare --fork --pid --mount-proc readlink /proc/self
131.TQ
1321
133.br
134Establish a PID namespace, ensure we're PID 1 in it against newly mounted
135procfs instance.
136.TP
137.B $ unshare --map-root-user --user sh -c whoami
138.TQ
139root
140.br
141Establish a user namespace as an unprivileged user with a root user within it.
0490a6ca
KZ
142.TP
143.TQ
144.B # touch /root/uts-ns
145.TQ
146.B # unshare --uts=/root/uts-ns hostanme FOO
147.TQ
148.B # nsenter --uts=/root/uts-ns hostname
149.TQ
150FOO
151.TQ
152.B # umount /root/uts-ns
153.br
154Establish a persistent UTS namespace, modify hostname. The namespace maybe later entered
155by nsenter. The namespace is destroyed by umount the bind reference.
4205f1fd 156.SH SEE ALSO
8323d9fd 157.BR unshare (2),
c07f86e7
KZ
158.BR clone (2),
159.BR mount (8)
0490a6ca
KZ
160.SH AUTHORS
161.UR dottedmag@dottedmag.net
162Mikhail Gusarov
163.UE
164.br
165.UR kzak@redhat.com
166Karel Zak
167.UE
4205f1fd 168.SH AVAILABILITY
601d12fb
KZ
169The unshare command is part of the util-linux package and is available from
170ftp://ftp.kernel.org/pub/linux/utils/util-linux/.