2

I would like to be able to use the sudo command in a chroot environment.

I start the chroot as follows:

chroot /debian-squeeze /bin/bash

Now I'm logged in as root in the chroot. I can do su user to log in as a user named user. Now, sudo does not work:

user@HD:/$ sudo ls
sudo: must be setuid root

Some diagnostics:

user@HD:/$ which sudo
/usr/bin/sudo

user@HD:/$ ls -al /usr/bin/sudo
-rwsr-xr-x 2 root root 143884 May 23  2012 /usr/bin/sudo

user@HD:/$ ls -aln /usr/bin/sudo
-rwsr-xr-x 2 0 0 143884 May 23  2012 /usr/bin/sudo

root@HD:/# cat /etc/sudoers
Defaults    env_reset
root    ALL=(ALL) ALL
user ALL=(ALL) ALL
%sudo ALL=(ALL) ALL

As root, I can execute sudo without error.

Can anyone explain me why sudo (or setuid) does not work like this?

  • This page might explain what you are after. – Cipher Menial Dec 10 '12 at 2:41
  • @Simplexion I see nothing on that page that might answer this question. – Michael Hampton Dec 10 '12 at 3:48
  • 1
    Show output of mount – daisy Dec 10 '12 at 3:52
4

My guess is that /debian-squeeze is on a separate filesystem mounted without defaults or suid. The kernel will ignore the setuid bit on filesystems mounted without suid (defaults implies suid). To fix it:

mount -o remount,suid /debian-squeeze
  • If su works than this is not the case... – Didi Kohen Dec 11 '12 at 15:06
  • Thanks, this was indeed the solution. (su worked because I was already root user when I executed su.) – Matthijs Melissen Dec 12 '12 at 10:19
  • Be carefull, someone can now go to /debian-squeeze without chroot and use sudo. – ctrl-alt-delor Jul 15 '16 at 8:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.