#!/bin/bash
#this is chroot creat. sh
Read-p "User chroot directory" dir
list= "Bash ls cat grep pwd"
Read-p "Username:" username
Useradd $username && mkdir-p/home/$username && echo "12345" | passwd--stdin $username &>/dev/null
echo "User $username is changed"
Mkdir-p $dir/bin Home Lib Lib64
cp-rp/home/$username/$dir/home/
For I in $list
Do
Base= ' which $i '
Cp-v "$BASE" "${dir}${base}"
Done
Mkdir-p $dir/lib/x86_64-linux-gnu/
For I in $list
Do
Base= ' which $i '
Nix= "$ (ldd $base | egrep-o '/lib.*\.[ 0-9] "
For a in $NIX
Do
Cp-v "$a" "${dir}${a}"
Done
Done
awk "/match| chrootdirectory/"/etc/ssh/sshd_config &>/dev/null
If [$?-ne 0]
Then
Sed-i.bak ' S/match user.*/match User $username/g ' s/chroot.*/chrootdirectory $dir/g '/etc/ssh/sshd_config
echo "File to replace complete!"
Service SSH Restart
#echo "Match User" $username >>/etc/ssh/sshd_config
# echo "Chrootdirectory" $dir >>/etc/ssh/sshd_config
Else
echo "Match User" $username >>/etc/ssh/sshd_config
echo "Chrootdirectory" $dir >>/etc/ssh/sshd_config
echo "File changes to complete!"
Service SSH Restart
Fi
echo "Chroot completing"
Chroot Build Script