Docker image to create a container exposing a ssh service with chroot features.
Example of usage
Run a container mouting a docker host directory in the /home volume and create all users required in the container to give restrictive ssh and sftp access to their /home subdirectory
list of commands exposed
bash sh, ls, cp, mv, mkdir, touch, vi, cat, sed, date, bunzip2, bzip2, chmod, egrep, fgrep, grep, gunzip, gzip, ln, more, ping, rm, tar, uname', rsync, scp, clear, perl, vi, curl, wget, basename, pager, git, git-receive-pack, git-shell, git-upload-archive, git-upload-pack
$ git clone https://github.com/shyd/docker-sshd.git ./sshd
$ git clone https://github.com/shyd/docker-ssh-chroot.git ./ssh-chroot
$ docker build -t shyd/sshd ./sshd
$ docker build -t shyd/ssh-chroot ./ssh-chroot
Run the image as a container
$ docker run -d -p 2222:22 -v /path/host:/home --name sshd --privileged shyd/ssh-chroot
- option --privileged required to give mount permissions inside the container (see here >)
$ docker exec -it sshd /bin/bash
bash@sshd $ /chroot.sh adduser -u soletic -id 10001
The command creates a user soletic and an isolated chroot environment :
- /chroot/soletic : his chroot environment
- /chroot/soletic/home : mounting point of /home/soletic
- /home/soletic/.ssh/authorized_keys created
- /chroot/soletic/credentials contains the password generated
If the real home directory of soletic user is for example /home/soletic/volumes/www, run the image setting up the environment variable CHROOT_USER_HOME_BASEPATH :
$ sudo docker run -d -p 2222:22 -v /path/host:/home -e CHROOT_USER_HOME_BASEPATH=/volumes/www --name sshd --privileged soletic/ssh-chroot:latest
And the command creating the user will mount /home/soletic/volumes/www in /chroot/soletic/home
$ sudo docker exec -it sshd /bin/bash
bash@sshd $ /chroot.sh deluser -u soletic
The file .sshusers and stored inside the home indexes all users created. If you don't want to lose the list, mount the volume /home with a host directory and often backup it.
If you want to add others commandes like php or mysql or ruby, you can create a new image extending this image with a plugin mechanism to setup the chroot environment.
See this repository for an example with php and mysql >
Documentation used to create this docker image :