How-to Enable Jailed Shells
Related Documentation:
Prerequisites
Last Updated for InterWorx version 3.0.1
| You probably don’t need to do this. All servers installed with InterWorx-CP versions 2.1.0 and later already have this taken care of. |
| This process is only required for servers that DO NOT have /usr/sbin/jk_chrootsh in the Default Shell drop-down on the Shell Users page. |
Purpose
The jk_chrootsh jailed shell is one of several shell options you can give to a user. What distinguishes the jailed shell from the other shell options is that the user, once logged in to the server, will have a changed restricted directory. Specifically, the user’s / will actually be the system’s /chroot/ directory and the user will not be able to navigate out of the /chroot directory. This provides additional security when offering users shell access to the server, as they will only be able to access a restricted, and controlled, portion of the server. If you are upgrading from a previous version of InterWorx-CP, you will need to follow the steps below to enabled jailed shells.
Procedure - Initial Preparation
SSH in to the server.
suto therootuserStop all services that are using resources on
/home. The list of services to be stopped will vary, depending on your server setup, but InterWorx-CP and Apache will need to be stopped:[root@test-box ~]# service iworx stop [root@test-box ~]# service httpd stop
You can check to see what is using the
/homedirectory by using thelsofcommand:[root@test-box ~]# lsof /home
If there is no output, that means no resources are using
/home.Determine if
/homeis a directory or a mounted partition:[root@test-box ~]# df -h | grep /home
If
/homeis a directory, you will see this:[root@test-box ~]# mount | grep /home [root@test-box ~]#
That is, you will not get any output, indicating
/homeis a directory.If
/homeis a partition, you will see something similar to this:[root@test-box ~]# mount | grep /home /dev/md5 on /home type ext3 (rw,noatime,usrquota,grpquota) [root@test-box ~]#
This indicates
/homeis a partition. Also, make note of the device as you will need it later. In the example above, the device is/dev/md5.
Continue on to the corresponding section below.
Procedure - /home is a Directory
| If /home is a directory on your server, follow this procedure |
Create the
/chrootdirectory:[root@test-box ~]# mkdir /chroot
Set the permissions on the
/chrootdirectory:[root@test-box ~]# chmod 711 /chroot
Move the
/homedirectory into thechrootdirectory:[root@test-box ~]# cd / [root@test-box ~]# mv /home /chroot [root@test-box ~]# chmod 711 /chroot/home
Symlink the
/homedirectory to/chroot/homeso all your paths to/homestill work correctly:[root@test-box ~]# ln -fs /chroot/home /home
When you next access the ♦ Shell Users page in NodeWorx, InterWorx-CP will generate the rest of the needed jailing directories in
/chroot. Navigate there now.There should now be the /usr/sbin/jk_chrootsh option in the Shell drop-down list.
Procedure - /home is a Partition
| If /home is a partition on your server, follow this procedure |
Unmount the
/homepartition:[root@test-box ~]# cd / [root@test-box ~]# umount /home
Delete the
/homedirectory:[root@test-box ~]# rm -r /home
Be sure that the /home directory is unmounted, otherwise this will delete all your data, including the InterWorx-CP installation Open
/etc/fstabin your editor of choice. Look for a line similar to:/dev/md5 /home ext3 defaults,noatime,usrquota,grpquota 1 2
or
LABEL=/home /home ext3 defaults,noatime,usrquota,grpquota 1 2
Specifically, you are looking for
/homein the second column.Replace
/homein the second column with/chroot. If your/etc/fstabalso hasLABEL=/homein the first column, replace it with the device you found above. For example:/dev/md5 /chroot ext3 defaults,noatime,usrquota,grpquota 1 2
Save and exit the file.
Make the
/chrootdirectory, andchmodit711:[root@test-box ~]# mkdir -p /chroot [root@test-box ~]# chmod 711 /chroot
Mount the
/chrootpartition:[root@test-box ~]# cd / [root@test-box ~]# mount /chroot
Make the
/chroot/homedirectory and chmod it711:[root@test-box ~]# mkdir /chroot/home [root@test-box ~]# chmod 711 /chroot/home
Move everything in
/chrootin to/home:[root@test-box ~]# mv /chroot/* /chroot/home
Symlink the
/homedirectory to/chroot/homeso all your paths to /home still work correctly:[root@test-box ~]# ln -fs /chroot/home /home
When you next access the ♦ Shell Users page in NodeWorx, InterWorx-CP will generate the rest of the needed jailing directories in
/chroot. Navigate there now.There should now be the /usr/sbin/jk_chrootsh option in the Shell drop-down list.
If you deem that your users need access to another command you use the jk_cp command from the root shell to add the command you want to enable e.g. jk_cp /chroot /usr/bin/command-you-want-to-install |
