1 # schsh: Restricted file access via SSH
5 Welcome to [schsh](https://www.ralfj.de/projects/schsh), a schroot-based shell.
7 Its purpose is simple: I want to provide users with scp, sftp and rsync access
8 to my server, such that they can only operate in a certain subdirectory.
9 There are plenty of solutions for this problem out there, and all have one
11 You need to manually set up a bunch of chroots, and copy the files needed for
12 scp, sftp and rsync into them.
14 I didn't like that, so here is my alternative solution: Use schroot for the
15 chroots. This gets OpenSSH out of the loop when it comes to chroots, instead
16 the relevant users get a special shell (schsh, the schroot shell). That shell
17 essentially calls schroot and runs the desired command inside the chroot. It
18 also provides some very basic command restriction (so that you can allow scp,
19 sftp and rsync and nothing else).
21 Unfortunately, this still needs a (s)chroot to be set up for each user, but at
22 least no files have to be copied: Instead, schroot is configured to bind-mount
23 the relevant system folders into the user-chroot. Hence no files are
24 duplicated, and system updates to the relevant tools are applied inside the
25 chroots automatically. For additional hardening, these bind-mounts are
26 configured to be read-only and no-setuid, while the only user-writeable folder
31 Before you start, make sure you have the dependencies installed:
32 schsh needs [Python 3](http://www.python.org) (I tested it with
33 version 3.2) and [schroot](https://wiki.debian.org/Schroot)
34 (version 1.6 or newer).
36 Installation is simple: Just run `make install`. That will copy some files
37 to `/usr/local/bin`, and some configuration to `/etc/schroot/`.
38 Before you create any users, make sure the directory `/var/lib/schsh` and a
39 group called `schsh` exist.
41 You should also set up SSH to disallow port forwarding for users controlled by
42 schsh. See `sshd_config` in the source folder for an appropriate snippet
43 of OpenSSH configuration.
45 Before you can set up schsh for a user, you need to create it first:
47 adduser sandboxed --disabled-password
49 Any existing user can be "sandboxed" by running:
53 This does the following:
55 * Change the user's shell to `/usr/local/bin/schsh`
56 * Create a chroot base in `/var/lib/schsh/sandboxed` with some empty
57 subfolders as well as `/etc/passwd` and `/etc/group` containing
58 only root, this user and the `schsh` group
59 * Add the user to the `schsh` group
60 * Set up a schroot called `schsh-sandboxed` for the given folder, and an
61 fstab file in `/etc/schroot/schsh` used by this schroot
63 Now if the user logs in via SSH, `/usr/local/bin/schsh` will be executed,
64 and it will lock the user into the schroot `schsh-sandboxed`. It will
65 only see some system folders and a folder called `/data` mapped to
66 `/home/sandboxed/data`. If you want to give the user access to more
67 folders, or another folder, simply edit `/etc/schroot/schsh/sandboxed.fstab`.
68 The only part of schsh writing any files is `makeschsh`, so you can change
69 the users' schroot configurations at your will.
73 There is not much to configure at the moment. However, there are some
74 global variables at the top of both `schsh` and `makeschsh` to
75 change the base paths, and to tell which commands are allowed.
79 You can find the sources in the [git
80 repository](http://www.ralfj.de/git/schsh.git) (also available [on
81 GitHub](https://github.com/RalfJung/schsh)). They are provided under the
82 [GPLv3](https://www.gnu.org/licenses/gpl.html). In addition, all files except
83 for `schsh-rrsync` are provided under the
84 [GPLv2](https://www.gnu.org/licenses/old-licenses/gpl-2.0.html) or (at your
85 option) any later version of the GPL. See the file `LICENSE-GPL3` for more
90 If you found a bug, or want to leave a comment, please
91 [send me a mail](mailto:post-AT-ralfj-DOT-de).