====== Команда chroot ======
* [[http://ru.wikipedia.org/wiki/Chroot]]
* [[http://linoxide.com/ubuntu-how-to/configure-chroot-environment-ubuntu-14-04/|How to Configure Chroot Environment in Ubuntu 14.04]]
* [[http://www.ouah.org/chroot-break.html|How to break out of a chroot jail]]
===== Изолированный shell =====
==== Debian/Ubuntu ====
=== Создание окружения "в ручную" ===
Примечание, в качестве исходных файлов здесь часто будут линки, превращающиеся в обычные файлы с такими же именами при копировании
# ldd /bin/bash
# ldd /bin/cat
# ldd /usr/bin/file
# man file
# cat makechroot.sh
mkdir /var/www/bin
mkdir /var/www/usr/
mkdir /var/www/usr/bin
mkdir -p /var/www/usr/share/misc
cp /bin/bash /var/www/bin/
cp /bin/cat /var/www/bin/
cp /usr/bin/file /var/www/usr/bin/
cp /usr/bin/date /var/www/usr/bin/
cp /usr/share/misc/magic.mgc /var/www/usr/share/misc/
mkdir /var/www/lib/
mkdir /var/www/lib64
mkdir /var/www/lib/x86_64-linux-gnu/
mkdir -p /var/www/usr/lib/x86_64-linux-gnu/
cp /lib64/ld-linux-x86-64.so.* /var/www/lib64/
cp /lib/x86_64-linux-gnu/libtinfo.so.* /var/www/lib/x86_64-linux-gnu/
cp /lib/x86_64-linux-gnu/libdl.so.* /var/www/lib/x86_64-linux-gnu/
cp /lib/x86_64-linux-gnu/libc.so.* /var/www/lib/x86_64-linux-gnu/
cp /lib/x86_64-linux-gnu/libz.so.* /var/www/lib/x86_64-linux-gnu/
#debian11_12 cp /lib/x86_64-linux-gnu/libbz2.so.* /var/www/lib/x86_64-linux-gnu/
#debian12/ubuntu24 cp /lib/x86_64-linux-gnu/liblz* /var/www/lib/x86_64-linux-gnu/
cp /usr/lib/x86_64-linux-gnu/libmagic.so.* /var/www/usr/lib/x86_64-linux-gnu/
# sh makechroot.sh
=== Создание окружения через debootstrap ===
* [[https://wiki.debian.org/ru/Debootstrap]]
debian# apt install debootstrap
debian# lsb_release -a
debian# debootstrap --variant=minbase --arch amd64 buster /var/www/
==== CentOS ====
* [[http://www.serverschool.com/dedicated-servers/how-to-build-a-chroot-environment-in-centos/|How to Build a Chroot Environment in CentOS]]
==== Тестирование ====
# chroot /var/www/ /bin/bash
или
# unshare -R /var/www /bin/bash
# echo *
# cat index.html
# file -bi index.html
# cat /etc/passwd
===== shell inetd web сервер в chroot =====
* [[Сервис INETD]]
==== Debian/Ubuntu====
# mkdir /var/www/sbin
# cp /usr/local/sbin/webd /var/www/sbin/
# cat /var/www/sbin/webd
...
base=/
log=/webd.log
...
===== Поиск всех процессов в chroot =====
* [[https://support.cpanel.net/hc/en-us/articles/1500012454701-How-To-Find-The-List-Of-All-The-Chroot-ed-Processes-On-The-System|How To Find The List Of All The Chroot-ed Processes On The System?]]
for file in `find /proc/ -type l -name "root" -print 2> /dev/null | grep -Eiv /task/ 2> /dev/null`; do PID=`ls -d $file 2> /dev/null| awk -F "/" '{print $3}'` && printf "%s = %s = %s\n" "$PID" `ps -p "$PID" 2> /dev/null | tail -n1 | awk '{print $4}'` `readlink $file 2> /dev/null` | grep -Eiv "(= /$|^\s*=\s*$|^.*?=\s*$)";done