#!/bin/bash # # Usage: ./create_chroot_env5 username # # Here specify the apps you want into the enviroment APPS="/bin/bash /bin/cat /bin/cp /bin/chmod /bin/ls \ /bin/mkdir /bin/mv /bin/touch /bin/pwd /bin/rm /bin/vi \ /usr/bin/id /usr/local/bin/scp /usr/local/bin/sftp \ /usr/local/libexec/sftp-server" # Sanity check if [ "$1" = "" ] ; then echo " Usage: ./create_chroot_env5 username" exit fi # Obtain username and HomeDir CHROOT_USERNAME=$1 HOMEDIR=`grep /etc/passwd -e "^$CHROOT_USERNAME" | cut -d':' -f 6` mkdir $HOMEDIR chown root:root $HOMEDIR cd $HOMEDIR # Create writeable Directories only for you mkdir {data,public_html} chown $1:$1 {data,public_html} chmod 711 {data,public_html} # Create Directories no one will do it for you mkdir {etc,bin,dev} mkdir -p usr/bin mkdir -p usr/local/{bin,libexec} MAKEDEV -d dev -x null random zero # Create short version to /usr/bin/groups # On some system it requires /bin/sh, # which is generally unnessesary in a chroot cage echo "#!/bin/bash" > usr/bin/groups echo "id -Gn" >> usr/bin/groups # Add some users to ./etc/paswd grep /etc/passwd -e "^root" -e "^$CHROOT_USERNAME" > etc/passwd grep /etc/group -e "^root" -e "^$CHROOT_USERNAME" > etc/group # Copy the apps and the related libs for prog in $APPS; do cp $prog ./$prog # obtain a list of related libraryes ldd $prog > /dev/null if [ "$?" = 0 ] ; then LIBS=`ldd $prog | awk '{ print $3 }'` for l in $LIBS; do mkdir -p ./`dirname $l` > /dev/null 2>&1 cp $l ./$l done fi done # From some strange reason these 3 libraries are not in the ldd output, # but without them some stuff will not work, like usr/bin/groups cp /lib/{libnss_compat.so.2,libnsl.so.1,libnss_files.so.2} ./lib/ # My original openssh'settings needs cp -L /lib/ld-linux.so.2 ./lib/ cp /etc/{ld.so.cache,ld.so.conf,localtime} ./etc/