9

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

Stephen Rauch
  • 47,830
  • 31
  • 106
  • 135
Karim Kouznetsov
  • 133
  • 1
  • 3
  • 8
  • Take a look: http://stackoverflow.com/questions/3737008/how-to-run-a-command-in-a-chroot-jail-not-as-root-and-without-sudo – Leo Chapiro Apr 13 '13 at 07:17

4 Answers4

10

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.

Stephen Rauch
  • 47,830
  • 31
  • 106
  • 135
bash.d
  • 13,029
  • 3
  • 29
  • 42
5

You could try fakechroot chroot

kvz
  • 5,517
  • 1
  • 42
  • 33
4

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

Community
  • 1
  • 1
Rafael van Horn
  • 591
  • 4
  • 3
0

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
rickfoosusa
  • 1,061
  • 19
  • 26