用户登录后,进入受限的文件系统
背景: 受限用户为demo,chroot根为/user/demo
拷贝命令到特定受限的目录
/bin/cp /lib64/ld-linux-x86-64.so.2 /user/demo/lib64/cmds="mount clear top ls bash touch more less awk sed vim mkdir"for cmd in $cmdsdoa=`which $cmd`cp $a /user/demo/bin/ldd $a | awk '{print $3}' | while read linedoif [[ $line == /lib64* || $line == /usr/* ]]thenpath=$(dirname $line)if [ ! -d /user/demo$path ]thenmkdir -p /user/demo$pathfi/bin/cp $line /user/demo$linefidonedone
拷贝profile文件
mkdir -p /user/demo/etc/bin/cp /etc/profile /user/demo/etc/profile/bin/cp /etc/bashrc /user/demo/etc/bashrc
生成dev下的常用设备
mkdir -p /usr/demo/dev/bin/mknod -m 0666 /user/demo/dev/null c 1 3/bin/mknod -m 0666 /user/demo/dev/random c 1 8/bin/mknod -m 0666 /user/demo/dev/urandom c 1 9
使用proc与shm目录
mkdir -p /user/demo/dev/shmmkdir -p /user/demo/procmount --bind /dev/shm /user/demo/dev/shmmount --bind /proc /user/demo/proc
终端信息配置拷贝
mkdir -p /user/demo/usr/share/bin/cp -r /usr/share/terminfo /user/demo/usr/share/terminfo
生成特定的bash_profile
echo "export PATH=$PATH/bin" > /user/demo/home/demo/.bash_profileecho "export TERMINFO=/usr/share/terminfo" >> /user/demo/home/demo/.bash_profilechown demo:demo /user/demo/home/demo/.bash_profile
