7 This is schsh, a schroot-based shell.
9 The purpose is simple: I want to provide users with scp, sftp and rsync access
10 to my server, such that they can only operate in a certain subdirectory.
11 There are plenty of solutions for this problem out there, and all have one
13 You need to manually set up a bunch of chroots, and copy the files needed for
14 scp, sftp and rsync into them.
16 I didn't like that, so here is my alternative solution: Use schroot for the
17 chroots. This gets OpenSSH out of the loop when it comes to chroots, instead
18 the relevant users get a special shell (schsh, the schroot shell). That shell
19 essentially calls schroot and runs the desired command inside the chroot. It
20 also provides some very basic command restriction (so that you can allow scp,
21 sftp and rsync and nothing else).
23 Unfortunately, this still needs a (s)chroot to be set up for each user, but at
24 least no files have to be copied: Instead, schroot is configured to bind-mount
25 the relevant system folders into the user-chroot. Hence no files are
26 duplicated, and system updates to the relevant tools are applied inside the
27 chroots automatically. For additional hardening, these bind-mounts are
28 configured to be read-only and no-setuid, while the only user-writeable folder
35 Before you start, make sure you have the dependencies installed:
36 schsh needs [Python 3][0] (I tested it with version 3.2) and [schroot][1]
37 (version 1.6 or newer).
39 Installation is simple: Just run ```make install```. That will copy some files
40 to ```/usr/local/bin```, and some configuration to ```/etc/schroot/```.
41 Before you create any users, make sure the directory ```/var/lib/schsh``` and a
42 group called ```schsh``` exist.
44 You should also set up SSH to disallow port forwarding for users controlled by
45 schsh. See ```sshd_config``` in this folder for an appropriate snippet of
46 OpenSSH configuration.
48 Before you can set up schsh for a user, you need to create it first:
50 adduser sandboxed --disabled-password
52 Any existing user can be "sandboxed" by running
56 This does the following:
58 * Change the user's shell to ```/usr/local/bin/schsh```
59 * Create a chroot base in ```/var/lib/schsh/sandboxed``` with some empty
60 subfolders as well as ```/etc/passwd``` and ```/etc/group``` containing
61 only root, this user and the ```schsh``` group
62 * Add the user to the ```schsh``` group
63 * Add a schroot called schsh-sandboxed for the given folder, and an fstab file
64 in ```/etc/schroot/schsh``` used by this schroot
66 Now if the user logs in via SSH, ```/usr/local/bin/schsh``` will be executed,
67 and it will lock the user into the schroot ```schsh-sandboxed```. It will
68 only see some system folders and a folder called ```/data``` mapped to
69 ```/home/sandboxed/data```. If you want to give the user access to more folders,
70 or another folder, simply edit ```/etc/schroot/schsh/sandboxed.fstab```.
71 The only part of schsh writing any files is ```makeschsh```, so you can change
72 the users' schroot configurations at your will.
74 [0]: http://www.python.org
75 [1]: http://packages.qa.debian.org/s/schroot.html
80 There is not much to configure at the moment. However, there are some
81 global variables at the top of both ```schsh``` and ```makeschsh``` to
82 change the base paths, and to tell which commands are allowed.