Karim Kouznetsov
Karim Kouznetsov

Reputation: 133

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())

Upvotes: 9

Views: 13337

Answers (4)

bash.d
bash.d

Reputation: 13207

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.

Upvotes: 10

Rafael van Horn
Rafael van Horn

Reputation: 621

Try a tool called PRoot It's based on ptrace and syscall instrumentation and one of possible usecases is to achieve something like chroot.

Upvotes: 4

rickfoosusa
rickfoosusa

Reputation: 1139

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

Upvotes: 0

kvz
kvz

Reputation: 5885

You could try fakechroot chroot

Upvotes: 5

Related Questions