Scenario: Your AIX server has OpenSSH installed and sFTP configured. How do you restrict sFTP users from accessing other shells (like ksh, bash, csh, scp, ftp, etc)? How do you prevent them from traversing through your directories and potentially doing all sorts of damage?
The answer: Set up rssh with chroot jail. Restricted shell (rssh) is a replacement for the standard shell (in AIX’s case, ksh) to be used with OpenSSH that lets you restrict shell access to only sftp and scp. It supports chroot jail which is a method to sandbox users and programs in a specific directory.
How do you set it up? Russell Martin wrote an excellent article with detailed explanations and instructions on the subject. I recommend that you read the article to understand what we’re trying to achieve.
Ok, why am I writing this post then? Well, even with the abundance of information from Russell’s article, it still took me a long time to set it up on an AIX 5.3ML6 server running OpenSSH 4.3p2. So, I’m writing down everything that I’ve done just in case someone got stuck like me.
(1) Installing rssh
rpm --install gcc-4.0.0-1.aix5.3.ppc.rpm
gunzip -d rssh-2.3.2.tar.gz
tar xvf rssh-2.3.2.tar
export ac_cv_func_malloc_0_nonnull=yes
Now we can start to run the commands:./configure
make
su root
make install
However, in my case sftp-server is located in the /usr/sbin directory, so for the first command, I have to do this instead:./configure --with-sftp-server=/usr/sbin/sftp-server
(2) Creating an user and chroot jail
cd /
command, he will arrive in the /var/file_transfer directory of the server, but to him, he is already in the root directory.smit user
sftpuser
as the User NAME./var/file_transfer/sftpuser
as the HOME directory./usr/bin/ksh
as the Initial PROGRAM for now.smit user
smit user
sftpuser
as the User NAME and proceed./usr/bin/rssh
as the Initial PROGRAM and proceed to save the changes. Now, we’re done creating the user in our system.chmod 755 chroot.sh
Before you run the script create the chroot directory first:cd /var
mkdir file_transfer
Then, edit the paths in the script:CHROOTPATH=/var/file_transfer #defines the path of your chroot directory (the directory where you want to confine users to).
USER_HOME_DIR=sftpuser #defines the path of the user's home relative to the CHROOTPATH
USER_NAME=sftpuser #defines the user name
GROUP_NAME=staff #defines the user group
SFTP_PATH=/usr/sbin/sftp-server
SCP_PATH=/usr/bin/scp
RSSH_PATH=/usr/bin/rssh
CHROOT_HELPER_PATH=/usr/local/libexec/rssh_chroot_helper
LDD_PATH=/usr/bin/ldd
KSH_PATH1=/usr/bin/ksh93
KSH_PATH2=/usr/bin/ksh
PWD_PATH1=/bin/pwd
PWD_PATH2=/usr/bin/pwd
LIB_CRYPTO_PATH=/opt/freeware/lib/libcrypto.a
LIB_C_PATH=/usr/lib/libc.a
LIB_CRYPT_PATH=/usr/lib/libcrypt.a
After changing the paths, run the script:./chroot.sh
logfacility = LOG_USER
allowsftp
umask = 022
chrootpath = "/var/file_transfer"
Congratulations! You have finished setting up rssh with chroot jail. Now you can sFTP in and see if all works fine.
In you run into any problems like the dreadful Connection Closed, you will have to check the syslog to see what the problem is.
I have read your documentation carefully as you stated and I am still getting the error: fatal error identifying the correct command (This should never happen). any clue what is going on here? Thanks, Joe
Hi Joe, what firmware are you running now?
At which step did the error occur?