Hi folks
I wanted to setup chroot for sftp in Redhat linux 9.0 and I have done
the following procedure
1.run the sscript
#!/bin/sh
CHROOT_DIR=/chroot
REQUIRED_CHROOT_FILES=" /bin/cp /bin/ls /bin/mkdir /bin/mv /bin/rm /bin/rmdir /bin/sh /usr/local/libexec/sftp-server"
# Create CHROOT_DIR
[ ! -d $CHROOT_DIR ] && mkdir $CHROOT_DIR
cd $CHROOT_DIR
# Copy REQUIRED_CHROOT_FILES and shared library dependencies
# to chroot environment
for FILE in $REQUIRED_CHROOT_FILES
do
DIR=`dirname $FILE | cut -c2-`
[ ! -d $DIR ] && mkdir -p $DIR
cp $FILE `echo $FILE | cut -c2-`
for SHARED_LIBRARY in `ldd $FILE | awk '{print $3}'`
do
DIR=`dirname $SHARED_LIBRARY | cut -c2-`
[ ! -d $DIR ] && mkdir -p $DIR
[ ! -s "`echo $SHARED_LIBRARY | cut -c2-`" ] && cp
$SHARED_LIBRARY `echo $SHARED_LIBRARY | cut -c2-`
done
done
2. cd chroot
#mkdir dev
#mknod /dev/null c 1 3
#mknod /dev/null c 1 5
#mkdir etc
#touch passwd
3.
User creation
useradd test -d /chroot/home/test
4. grep test/etc/passwd >> /chroot/etc/passwd
After completing all the above steps if I do
#chroot /chroot
bash-2.05b# ls
bin dev etc home lib usr
bash-2.05b# cd /
bash-2.05b# ls
bin dev etc home lib usr
bash-2.05b#
It works great, but if I do ssh/sftp with "test" user (which i created)
[root@testsftp /]# ssh test@localhost
test@localhost's password:
-bash-2.05b$ ls
-bash-2.05b$ cd /
-bash-2.05b$ ls
bin chroot etc initrd lost+found mnt proc sbin usr
boot dev home lib misc opt root tmp var
-bash-2.05b$
WHAT TYPE OF MISTAKE I AM DOING HERE, WHY IT IS NOT WORKING.
HELP PLEASE ( Anyother procedure please)
I wanted to setup chroot for sftp in Redhat linux 9.0 and I have done
the following procedure
1.run the sscript
#!/bin/sh
CHROOT_DIR=/chroot
REQUIRED_CHROOT_FILES=" /bin/cp /bin/ls /bin/mkdir /bin/mv /bin/rm /bin/rmdir /bin/sh /usr/local/libexec/sftp-server"
# Create CHROOT_DIR
[ ! -d $CHROOT_DIR ] && mkdir $CHROOT_DIR
cd $CHROOT_DIR
# Copy REQUIRED_CHROOT_FILES and shared library dependencies
# to chroot environment
for FILE in $REQUIRED_CHROOT_FILES
do
DIR=`dirname $FILE | cut -c2-`
[ ! -d $DIR ] && mkdir -p $DIR
cp $FILE `echo $FILE | cut -c2-`
for SHARED_LIBRARY in `ldd $FILE | awk '{print $3}'`
do
DIR=`dirname $SHARED_LIBRARY | cut -c2-`
[ ! -d $DIR ] && mkdir -p $DIR
[ ! -s "`echo $SHARED_LIBRARY | cut -c2-`" ] && cp
$SHARED_LIBRARY `echo $SHARED_LIBRARY | cut -c2-`
done
done
2. cd chroot
#mkdir dev
#mknod /dev/null c 1 3
#mknod /dev/null c 1 5
#mkdir etc
#touch passwd
3.
User creation
useradd test -d /chroot/home/test
4. grep test/etc/passwd >> /chroot/etc/passwd
After completing all the above steps if I do
#chroot /chroot
bash-2.05b# ls
bin dev etc home lib usr
bash-2.05b# cd /
bash-2.05b# ls
bin dev etc home lib usr
bash-2.05b#
It works great, but if I do ssh/sftp with "test" user (which i created)
[root@testsftp /]# ssh test@localhost
test@localhost's password:
-bash-2.05b$ ls
-bash-2.05b$ cd /
-bash-2.05b$ ls
bin chroot etc initrd lost+found mnt proc sbin usr
boot dev home lib misc opt root tmp var
-bash-2.05b$
WHAT TYPE OF MISTAKE I AM DOING HERE, WHY IT IS NOT WORKING.
HELP PLEASE ( Anyother procedure please)