Setting Up a Chroot Jail With rssh in the Solaris 8 OSRussell Martin, May 2007 Introduction
The free
You can download and build
The
I'm certainly no expert when it comes to
It took me about 16 hours of frustrating trial and error to get my first Contents
Basic StepsThe basic steps are as follows:
Required FilesTo my knowledge, the files that need to be copied into your jail are as follows. (However, I've done this only on the Solaris 8 OS.)
I feel like I can't say this too many times: The files need to be placed in the jail directory in directories that mimic their placement in the root file system.
For instance, on the root file system,
So, if your jail was going to be in Library Files
The library files that any of these files need can be found by using the
Running $ ldd /opt/csw/libexec/sftp-server libcrypto.so.0.9.8 => /opt/csw/lib//libcrypto.so.0.9.8 librt.so.1 => /usr/lib/librt.so.1 libsocket.so.1 => /usr/lib/libsocket.so.1 libc.so.1 => /usr/lib/libc.so.1 libnsl.so.1 => /usr/lib/libnsl.so.1 libdl.so.1 => /usr/lib/libdl.so.1 libaio.so.1 => /usr/lib/libaio.so.1 libmp.so.2 => /usr/lib/libmp.so.2 /usr/platform/SUNW,Sun-Blade-100/lib/libc_psr.so.1 All of those library files have to be copied inside of the directory that is going to be the jail directory, and they must be placed in directories that mimic the directory structure of the root file system.
For example, my You could do all of this by hand, but I think it's easier to use a script, and I provide my script below. The ldd Command Doesn't Tell the Whole Story
Unfortunately,
Here's the command I used to run - $ truss -o /export/home/rmartin/truss_sftp-server.txt /opt/csw/libexec/sftp-server
Running
Then, I used - $ grep ^open /export/home/rmartin/truss_sftp-server.txt This gave me the following:
open("/var/ld/ld.config", O_RDONLY) Err#2 ENOENT
open("/opt/csw/lib//libcrypto.so.0.9.8", O_RDONLY) = 3
open("/usr/lib/librt.so.1", O_RDONLY) = 3
open("/usr/lib/libsocket.so.1", O_RDONLY) = 3
open("/usr/lib/libc.so.1", O_RDONLY) = 3
open("/usr/lib/libnsl.so.1", O_RDONLY) = 3
open("/usr/lib/libdl.so.1", O_RDONLY) = 3
open("/usr/lib/libaio.so.1", O_RDONLY) = 3
open("/usr/lib/libmp.so.2", O_RDONLY) = 3
open("/usr/platform/SUNW,Sun-Blade-100/lib/libc_psr.so.1",
O_RDONLY) = 3
open64("/dev/null", O_RDWR) = 3
Notice that in addition to the libraries that
(I also noticed that it is failing to open What to Check When Things Aren't Working
Unfortunately, /var/adm/messages:Aug 23 18:41:14 slccon01 elfexec: [ID 700856 kern.notice] ksh: Cannot find /usr/lib/ld.so.1 /var/adm/messages:Aug 23 18:41:14 slccon01 elfexec: [ID 700856 kern.notice] sftp-server: Cannot find /usr/lib/ld.so.1
In other words, both Copy Preserving Permissions
The first time I got my jail working, I had
This got things working, but it is a really bad idea, and once my initial elation from having the
jail functioning wore off, I soon realized that the user would have free reign inside the jail and be able to
break things or replace any files. I was wearing out my welcome on the
I blew away my jail, re-ran my script, and suddenly things were working as they should be. I'm not sure
why I had to use Make the User's Home Directory
Once you've created the user's home directory inside the jail, you need to either edit Example: - testrssh:x:301:301:rssh test account:/export/home/chroot/export/home/testrssh:/opt/csw/bin/rssh
Notice how the home directory is set to
Once the user is logged in, it will appear that their home directory is simply
Also, notice that their shell is set to Edit rssh.conf
The default My Script for Creating Chroot Jails
This is the script I developed for creating
This script does everything but edit the The script does not take command line arguments. Instead, you need to edit the lines that set environment variables within the script.
[Begin Script]
CHROOTPATH=/export/home/chroot
USER_HOME_DIR=export/home/testrssh
USER_NAME=testrssh
GROUP_NAME=testrssh
SFTP_PATH=/opt/csw/libexec/sftp-server
SCP_PATH=/opt/csw/bin/scp
RSSH_PATH=/opt/csw/bin/rssh
CHROOT_HELPER_PATH=/opt/csw/libexec/rssh_chroot_helper
LDD_PATH=/usr/bin/ldd
KSH_PATH1=/bin/ksh
KSH_PATH2=/usr/bin/ksh
PWD_PATH1=/bin/pwd
PWD_PATH2=/usr/bin/pwd
>>
CopyLibFiles(){
for aFile in `ldd ${currExecutable} | cut -d' ' -f3`; do
if [ ! -d ${CHROOTPATH}/`dirname ${aFile}` ]; then
mkdir -p ${CHROOTPATH}/`dirname ${aFile}`;
fi
cp -p ${aFile} ${CHROOTPATH}${aFile}
done;
}
>>
CopyExecutable(){
directoryPath=`dirname ${currExecutable}`
mkdir -p ${CHROOTPATH}${directoryPath}
cp -p ${currExecutable} ${CHROOTPATH}${directoryPath}
}
>>
# copy sftp-server and library files
# ==================================
currExecutable=${SFTP_PATH}
CopyExecutable
CopyLibFiles
>>
# copy scp and library files
# ==========================
currExecutable=${SCP_PATH}
CopyExecutable
CopyLibFiles
>>
# copy rssh and library files
# ===========================
currExecutable=${RSSH_PATH}
CopyExecutable
CopyLibFiles
>>
# copy rssh_chroot_helper and library files
# =========================================
currExecutable=${CHROOT_HELPER_PATH}
CopyExecutable
CopyLibFiles
# copy ldd and library files
# ==========================
currExecutable=${LDD_PATH}
CopyExecutable
CopyLibFiles
>>
# copy ksh and library files
# =========================
currExecutable=${KSH_PATH1}
CopyExecutable
CopyLibFiles
currExecutable=${KSH_PATH2}
CopyExecutable
CopyLibFiles
# copy pwd and library files
# =========================
currExecutable=${PWD_PATH1}
CopyExecutable
CopyLibFiles
currExecutable=${PWD_PATH2}
CopyExecutable
CopyLibFiles
>>
# copy file(s) from /etc
# ====================
mkdir -p ${CHROOTPATH}/etc
cp -p /etc/passwd ${CHROOTPATH}/etc
# create home directory in jail
# =============================
mkdir -p ${CHROOTPATH}/${USER_HOME_DIR}
chown ${USER_NAME}:${GROUP_NAME} ${CHROOTPATH}/${USER_HOME_DIR}
echo "Remember to edit /etc/passwd with absolute path to jailed /
home dir: ${CHROOTPATH}/${USER_HOME_DIR}"
# copy ld.so.1
# ============
cp -p /usr/lib/ld.so.1 ${CHROOTPATH}/usr/lib/
# create /dev/null in jail
# ========================
mkdir -p ${CHROOTPATH}/dev
cp -p /dev/null ${CHROOTPATH}/dev
[End Script]
What the Script CreatesSurprisingly, very few files ended up in my working jail. Here's the directory output: /export/home/chroot/ /export/home/chroot/opt /export/home/chroot/opt/csw /export/home/chroot/opt/csw/libexec /export/home/chroot/opt/csw/libexec/sftp-server /export/home/chroot/opt/csw/libexec/rssh_chroot_helper /export/home/chroot/opt/csw/lib /export/home/chroot/opt/csw/lib/libcrypto.so.0.9.8 /export/home/chroot/opt/csw/bin /export/home/chroot/opt/csw/bin/scp /export/home/chroot/opt/csw/bin/rssh /export/home/chroot/usr /export/home/chroot/usr/lib /export/home/chroot/usr/lib/librt.so.1 /export/home/chroot/usr/lib/libsocket.so.1 /export/home/chroot/usr/lib/libc.so.1 /export/home/chroot/usr/lib/libnsl.so.1 /export/home/chroot/usr/lib/libdl.so.1 /export/home/chroot/usr/lib/libaio.so.1 /export/home/chroot/usr/lib/libmp.so.2 /export/home/chroot/usr/lib/libelf.so.1 /export/home/chroot/usr/lib/libsecdb.so.1 /export/home/chroot/usr/lib/libcmd.so.1 /export/home/chroot/usr/lib/ld.so.1 /export/home/chroot/usr/platform /export/home/chroot/usr/platform/SUNW,Sun-Blade-100 /export/home/chroot/usr/platform/SUNW,Sun-Blade-100/lib /export/home/chroot/usr/platform/SUNW, Sun-Blade-100/lib/libc_psr.so.1 /export/home/chroot/usr/bin /export/home/chroot/usr/bin/ldd /export/home/chroot/usr/bin/ksh /export/home/chroot/usr/bin/pwd /export/home/chroot/bin /export/home/chroot/bin/ksh /export/home/chroot/bin/pwd /export/home/chroot/etc /export/home/chroot/etc/passwd /export/home/chroot/export /export/home/chroot/export/home /export/home/chroot/export/home/testrssh /export/home/chroot/dev /export/home/chroot/dev/null I had seen some advice to create a single jail for all your jailed users; however, after looking at that list of files, I don't think it would be unreasonable to isolate each user in a separate jail. Conclusion
Setting up a
If all else fails, you may want to try posting to the Good luck and happy chroot'ing! About the AuthorRussell Martin has worked for EDS, the Salt Lake City School District, and Packard Bell. Oh, yeah, he also received a computer science degree with an emphasis on software engineering from Weber State University. One more thing: He is the creator of nCalc, a calculator for notebook computers running Mac OS. Unless otherwise licensed, code in all technical manuals herein (including articles, FAQs, samples) is provided under this License. |
BigAdmin SubscriptionsBigAdmin Areas
BigAdmin Sun Center
BigAdmin Topics | |||