chroot
needs CAP_SYS_CHROOT
according to the manual. The unshare
command uses chroot.
The command unshare -UrR newroot/
will work without being run as root
, which makes sense since the -r
flag makes us root
inside the namespace, giving us the CAP_SYS_CHROOT
capability.
The problem begins when unshare -UR newroot/
doesn't require being run as root
, while unshare -U chroot newroot/
will give me the Operation not permitted
error. So in the first, I am not asking for being root
inside the user namespace, and the second is the same but trying to do it manually.
Checking the code, the only thing that happens when using -R
is setting the newroot
to optarg
, so I can't understand why in one example this works, and in the other, it doesn't.