How to create chrooted openSSH SFTP in Debian 4 (“etchy”)

Two years ago, I had a subject at university that consisted of developing our skills as Systems Administrator (its fullname was “Administración de sistemas informáticos“).

The main task was to configure a minimal Debian GNU/Linux 4 (“etchy”) to work as a server for a webpage which provided internet services. One of the things to do was to allow users to connect the server using openSSH SFTP, restricting the folders they could visit to the user’s home directory. I looked on the internet and the only easy and complete tutorial about this topic was this one., but some details differed slightly as it was written for Ubuntu users and not Debian.

I considered posting my result on the internet to make accesible to other the information I couldn’t get. I never did it because I didn’t have a blog; now the situation has changed, it’s time to post it (although -WARNING- the information may be out-of-date and there will be easier ways to perform this.


Folder “/users” will be considered to be the chroot folder.

1. Install rssh:

apt-get install rssh

2. Edit /etc/rssh.conf and ensure that the following field are configured:

chrootpath = “/users/”

The only transfer protocol allowed will be SFTP (we are discarding SCP, but it could have been added). The goal is to avoid any kind of connection except the safe transfer protocol SFTP.

3. Enter “rssh -v” in the console. We will get the following paths:

rssh config file =1
chroot helper path = /usr/lib/rssh/rssh_chroot_helper
scp binary path = /usr/bin/scp
sftp server binary = /usr/lib/openssh/sftp-server
cvs binary path = /usr/bin/cvs
rdist binary path = /usr/bin/rdist
rsync binary path = /usr/bin/rsync

3. Edit the executable file located in /usr/share/doc/rssh/examples/

Paths should be substituted for those that we got with the command “rssh -v”, so in this way:

scp_path = /usr/bin/scp
sftp_server_path = /usr/libexec/openssh/sftp-server
rssh_path = /usr/bin/rssh
chroot_helper_path = /usr/libexec/rssh_chroot_helper

will be:

scp_path = /usr/bin/scp
sftp_server_path = /usr/lib/openssh/sftp-server
rssh_path = /usr/bin/rssh
chroot_helper_path = /usr/lib/rssh/rssh_chroot_helper

4. Make the script executable:

chmod u+x

5. Run the script using the following line:

./ /users/

If there is an error related to, don’t worry, it isn’t unexpected.

6. By entering “ldd /usr/bin/sftp”, we will get the list of libraries that SFTP needs to run: =>  (0xffffe000) => /lib/tls/ (0x4001d000) => /usr/lib/i686/cmov/ (0x40030000) => /lib/tls/ (0x4016a000) => /usr/lib/ (0x4016e000) => /lib/tls/ (0x40182000) => /lib/tls/ (0x40199000) => /usr/lib/ (0x401c7000) => /usr/lib/ (0x401e3000) => /usr/lib/ (0x4025f000) => /lib/ (0x40284000) => /usr/lib/ (0x40287000) => /usr/lib/ (0x4028d000) => /lib/ (0x402a8000) => /lib/tls/ (0x402e9000) => /lib/tls/ (0x4041b000)
/lib/ (0x40000000)

The script has copied many libraries into the chroot (e. g., /usr/lib/ has been copied to /users/usr/lib/ How ever, some of them hasn’t been copied and we will have to do it manually. They are the following:


Nevertheless, it is very convenient to double check that all libraries has been copied inside the chroot properly, because their existence is vital for a proper running.

7. Enter:

add-shell /usr/bin/rssh

8. Set the users that are going to use chroot in the configuration file /etc/passwd, using the following format:


We are indicating the absolute path for their chroot folder, and that they should use /usr/bin/rssh as their bash.

9. Give user permission to rssh_chroot_helper:

chmod u+s /usr/lib/rssh/rssh_chroot_helper

10. Now it is the time to test your server:


11. If you get the error message “Connection closed”, don’t give up! Probably it will be fixed entering:

mknod -m 666 /users/dev/null c 1 3

Cross your fingers and reconnect, it should work now… If the line displayed looks like “sftp>”, it is very possible that everything is working properly. Enter “pwd” to check that the user is actually chrooted (it should return “/home/user_name” instead of “/users/home/user_name”).

If “pwd” return /users/home/user_name, check that the user’s bash is configured in passwd file as “/etc/bin/rssh”, not “/bin/bash”. If negative, the system is working without rssh and with no connection restrictions.

The last check: enter “ssh” to check that the connection is refused. It should not allow you to connect; in fact, that’s why we came throuhg all this. 😉

Leave a Reply

Your email address will not be published. Required fields are marked *