A small SFTP container using Alpine Linux and OpenSSH. Useful for developing and testing projects that need access to resources via SFTP.
If it is necessary to provide SSL keys to the container then create a folder at the location ssh-files/keys
and place the keys there. The following code segment creates the folder and generates both RSSA and EdDSA SHA-2 keys.
$ mkdir ssh-files/keys
$ ssh-keygen -t ed25519 -f ssh-files/keys/ssh_host-ed25519_key < /dev/null
$ ssh-keygen -t rsa -b 4096 -f ssh-files/keys/ssh_host-rsa_key < /dev/null
If the folder does not exist or does not contain any SSL keys the container will generate all necessary keys on run.
$ podman build --rm -t sftp-server -f ./Containerfile .
Use the following command will run the SFTP container on port 2022 using current user's information and the optional mapping to a local directory.
$ AUTHORIZED_KEYS=$(cat ~/.ssh/id_rsa.pub)
$ mkdir local
$ podman run -p 2022:22 --name "sftp-server" \
-e SFTP_AUTHORIZED_KEYS="${AUTHORIZED_KEYS}" \
-e SFTP_USERNAME="${USER}" \
-e SFTP_UID=$(id -u) \
-e SFTP_GID=$(id -g) \
-v ./local:"/home/${USER}" \
"sftp-server-instance"
The provided file docker.env
uses current user information to create the docker image. You can modify these values if necessary. Once set to the desired values you can create the docker container and run it using the docker-compose as displayed below.
$ set -a
$ source docker.env
$ docker-compose build
$ docker-compuse up -d