'does chroot() require root privileges?
When I try to use chroot with "." or the complete pathname as argument, perror tells me "Operation not permitted".
If the answer to my question is yes, is there another way to change root directory ? (Without barbarian methods using strcmp() / strncmp())
Solution 1:[1]
chroot can only be used by root him/her/itself. And no, there won't be any other way without compromising security.
From Wikipedia
Only the root user can perform a chroot. This is intended to prevent users from putting a setuid program inside a specially crafted chroot jail (for example, with a fake /etc/passwd and /etc/shadow file) that would fool it into a privilege escalation.
See here for the article.
Solution 2:[2]
You could try fakechroot chroot
Solution 3:[3]
Try a tool called PRoot It's based on ptrace and syscall instrumentation and one of possible usecases is to achieve something like chroot.
Solution 4:[4]
From user space, you can use the schroot command. Add a few lines to /etc/schroot/schroot.conf
[xenial]
description=Ubuntu 16.04 (xenial)
type=directory
directory=/srv/chroots/xenial
aliases=xenial-lts
profile=minimal
users=bob
personality=linux64
Then from your user account:
schroot -c xenial
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Stephen Rauch |
| Solution 2 | kvz |
| Solution 3 | Community |
| Solution 4 | rickfoosusa |
