title: How to run a command in a chroot jail not as root and without sudo?
body: <p>I'm setting up a minimal chroot and want to avoid having sudo or su in it but still run my processes as non-root. This is a bit of a trick as running chroot requiers root. I could write a program that does this that would look something like:</p>
  
  <pre><code>uid = LookupUser(args[username])  // no /etc/passwd in jail
  chroot(args[newroot])
  cd("/")
  setuids(uid)
  execve(args[exe:])
  </code></pre>
  
  <p>Is that my best bet or is there a standard tool that does that for me?</p>
  
  <hr>
  
  <p>I rolled my own <a href="https://stackoverflow.com/questions/3756610/does-anyone-see-any-problem-with-this-program">here</a>:</p>