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?

Thanks

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
        linux-gate.so.1 =>  (0xffffe000)
        libreadline.so.6 => /lib/libreadline.so.6 (0xb768d000)
        libdl.so.2 => /lib/libdl.so.2 (0xb7688000)
        libc.so.6 => /lib/libc.so.6 (0xb7528000)
        libncurses.so.5 => /lib/libncurses.so.5 (0xb74eb000)
        /lib/ld-linux.so.2 (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.