chroot environment

Hi, I’m set up a little chroot jail with bash, cp, ls, pwd, mv and rm, I
also edit the chrooted group and passwd files and remove all users leaving
only one, but when I type chroot jail_directory it always login as root, how
can I set it to login as the chroot user previously defined?


First of all: you have to provide the required dynamic libraries for the commands within within the jail at the proper positions. Use ldd to check what is required:

ldd /bin/bash =>  (0xffffe000) => /lib/ (0xb768d000) => /lib/ (0xb7688000) => /lib/ (0xb7528000) => /lib/ (0xb74eb000)
        /lib/ (0xb76ed000)

Then I believe only the super-user can invoke chroot, exceptions applying for FreeBSD and Cygwin.

I think you need to write a little program that does a chroot(), and then does a setuid() to change to the desired user.