How can I grant a user permissions to chroot? SOLVED

Quick to answer questions about finding your way around Linux Mint as a new user.
Forum rules
There are no such things as "stupid" questions. However if you think your question is a bit stupid, then this is the right place for you to post it. Stick to easy to-the-point questions that you feel people can answer fast. For long and complicated questions use the other forums in the support section.
Before you post read how to get help. Topics in this forum are automatically closed 6 months after creation.
Locked
nolag

How can I grant a user permissions to chroot? SOLVED

Post by nolag »

I currently need to do the following

sudo chroot /chroot/mint32

but then I end up as root in the chroot and need to do su ryan

I want to just do chroot /chroot/mint32 but I get chroot: cannot change root directory to /chroot/mint32: Operation not permitted
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 2 times in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
vincent

Re: How can I grant a user permissions to chroot?

Post by vincent »

From http://en.wikipedia.org/wiki/Chroot:
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. It also prevents chroot from being used as an unprivileged sandboxing mechanism (for example, for users to run and test untrusted applications downloaded from the Internet).
I don't know if it's possible to grant a non-root user the privileges to chroot, and I wouldn't recommend it either.
nolag

Re: How can I grant a user permissions to chroot?

Post by nolag »

vincent wrote:From http://en.wikipedia.org/wiki/Chroot:
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. It also prevents chroot from being used as an unprivileged sandboxing mechanism (for example, for users to run and test untrusted applications downloaded from the Internet).
I don't know if it's possible to grant a non-root user the privileges to chroot, and I wouldn't recommend it either.
I see, I was hoping to make a makefile that would do the following

make all
make
./script

where script has
chroot /chroot/mint32
cd <the directory>
make

(somehow changing the .o file location and the executable location)

That way I can compile for x86 and 64 at the same time.

If I need to be root I guess that I need to do sudo make all to have it work?
vincent

Re: How can I grant a user permissions to chroot?

Post by vincent »

"make" shouldn't need to be run as root or with sudo. "chroot" will, however.
nolag

Re: How can I grant a user permissions to chroot?

Post by nolag »

vincent wrote:"make" shouldn't need to be run as root or with sudo. "chroot" will, however.
Yeah well I can do the chroot as root then su to my account, but I still need a way to do this with a makefile. Any ideas? My main post about that is http://forums.linuxmint.com/viewtopic.php?f=47&t=52105
vincent

Re: How can I grant a user permissions to chroot?

Post by vincent »

Nope, I'm no good with makefiles and the like, sorry. :P
piratesmack

Re: How can I grant a user permissions to chroot?

Post by piratesmack »

Maybe something like

Code: Select all

#!/bin/bash

# Build 32-Bit version in background
sudo chroot /chroot/mint32 \
  su ryan -c /bin/bash -c "cd <32-Bit build folder> ; make" &

# build 64-Bit version
( cd <64-Bit build folder>
  make
)

# wait for 32-Bit version to finish
wait $!

# install 64-bit version to ~/Desktop/project/bin64
( cd <64-Bit build folder>
  make install DESTDIR="~/Desktop/project/bin64"
)

# install 32-Bit version to ~/Desktop/project/bin32 
( cd /chroot/mint32/<32-Bit build folder>
  make install DESTDIR="~/Desktop/project/bin32"
)

Assuming the Makefiles support DESTDIR
nolag

Re: How can I grant a user permissions to chroot?

Post by nolag »

Thanks for the reply, I found my own way to do it, but I will try to add your background thing so they can do it at once,

mv linux64/*.o linux64/*.d linux64/euchre .
make
mv *.o *.d euchre linux64
sudo mount /chroot/mint32/proc
sudo mount /chroot/mint32/home
sudo mount /chroot/mint32/tmp
sudo chroot /chroot/mint32 su ryan -c /bin/bash -c "cd ~/Desktop/CS246/game; make"
mv linux32/*.o linux32/*.d linux32/euchre .
mv *.o *.d euchre linux32

Thanks a million :D.
Locked

Return to “Beginner Questions”