I am unable to serve or execute a cgi file, and the cause seems to be that chroot is unable to find the cgi file when the permission is set to executable.

$>ls -l /var/www/my/dir/test.cgi
-rwxr-xr-x 1 root   daemon 67 May 19 15:45 /var/www/my/dir/test.cgi

$> chroot /var/www/ /my/dir/test.cgi
chroot: /my/dir/test.cgi: No such file or directory

Why can chroot not find the file?

If I change the permissions to remove execution, $> chmod 644 /var/www/my/dir/test.cgi, then run the same chroot command, the file is found, but permission is denied.

$> chroot /var/www/ /my/dir/test.cgi
chroot: /my/dir/test.cgi: Permission denied

The system is OpenBSD 5.7. I was testing using chroot to try to mimic what the httpd webserver does, because in the log /var/log/daemon, there is a similar message from slowcgi after trying to access the file: slowcgi[15587] execve /my/dir/index.cgi: No such file or directory

Thanks in advance.

  • Test.cgi looks pretty small. Is it a shell script? Is the shell available inside the chroot environment? May 18, 2015 at 22:24
  • actually the shell is not available I think. If I just enter $> chroot /var/www i get an error saying no shell is found. how should i set that?
    – hilcharge
    May 18, 2015 at 22:37
  • the test.cgi file is just a tIny print 'hello' perl script with shebang on top
    – hilcharge
    May 18, 2015 at 22:43
  • I'll defer to someone with more openbsd experience than I have. There's surely a straightforward method to install shell and perl and their dependencies in an alternative root, but I don't know offhand how to do it. May 18, 2015 at 23:00
  • oo just found [this]( docs.oracle.com/cd/E37670_01/E36387/html/ol_cj_sec.html) about using ldd <command> to find required dependencies for any command, then just copy paste em into same directory structure.
    – hilcharge
    May 18, 2015 at 23:09

1 Answer 1


You also need perl and all the dependencies of it in your chroot.

This files all have to be copied over to /var/www/usr/bin, /var/www/usr/lib and /var/www/usr/libexec:

# ldd /usr/bin/perl
        Start            End              Type Open Ref GrpRef Name
        0000001b26c00000 0000001b27002000 exe  1    0   0      /usr/bin/perl
        0000001da0006000 0000001da0418000 rlib 0    2   0      /usr/lib/libpthread.so.18.1
        0000001d2b68b000 0000001d2bc26000 rlib 0    1   0      /usr/lib/libperl.so.17.0
        0000001d6fed5000 0000001d702fd000 rlib 0    1   0      /usr/lib/libm.so.9.0
        0000001d8d017000 0000001d8d423000 rlib 0    1   0      /usr/lib/libutil.so.12.1
        0000001ddb924000 0000001ddbe10000 rlib 0    1   0      /usr/lib/libc.so.78.1
        0000001d7f700000 0000001d7f700000 rtld 0    1   0      /usr/libexec/ld.so
  • True that, along with all the perl modules used by the cgi script.
    – hilcharge
    May 30, 2015 at 23:40

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .