diff --git a/Dockerfile b/Dockerfile index bbfcadd7..e8972d91 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,8 @@ FROM debian:bullseye MAINTAINER Adrian Dvergsdal [atmoz.net] +ENV SSHD_PORT 22 + # Steps done in one RUN layer: # - Install packages # - OpenSSH needs /var/run/sshd to run @@ -15,6 +17,4 @@ COPY files/sshd_config /etc/ssh/sshd_config COPY files/create-sftp-user /usr/local/bin/ COPY files/entrypoint / -EXPOSE 22 - ENTRYPOINT ["/entrypoint"] diff --git a/README.md b/README.md index 9f923b84..ebf89be9 100644 --- a/README.md +++ b/README.md @@ -30,6 +30,8 @@ Easy to use SFTP ([SSH File Transfer Protocol](https://en.wikipedia.org/wiki/SSH own home directory, so make sure there are at least one subdirectory if you want them to upload files. - For consistent server fingerprint, mount your own host keys (i.e. `/etc/ssh/ssh_host_*`) +- Override port + - The container will internally listen on the port 22 (default port for sshd), but if for any reasons you want another port to be used internally instead of the default, you can change it with the env var SSHD_PORT # Examples @@ -64,6 +66,12 @@ sftp: command: foo:pass:1001 ``` +### Overriding the default port, so that sshd doesn't listen port 22 + +``` +docker run -e SSHD_PORT=1234 -p 1234:1234 -d atmoz/sftp foo:pass:::upload +``` + ### Logging in The OpenSSH server runs by default on port 22, and in this example, we are forwarding the container's port 22 to the host's port 2222. To log in with the OpenSSH client, run: `sftp -P 2222 foo@` diff --git a/files/entrypoint b/files/entrypoint index 9c3d6e35..54c8afb7 100755 --- a/files/entrypoint +++ b/files/entrypoint @@ -90,6 +90,9 @@ if [ -d /etc/sftp.d ]; then unset f fi + +sed -i "s/SSHD_PORT/$SSHD_PORT/" /etc/ssh/sshd_config + if $startSshd; then log "Executing sshd" exec /usr/sbin/sshd -D -e diff --git a/files/sshd_config b/files/sshd_config index 1308c8b2..80c71ba1 100644 --- a/files/sshd_config +++ b/files/sshd_config @@ -20,3 +20,5 @@ ChrootDirectory %h # Enable this for more logs #LogLevel VERBOSE + +Port SSHD_PORT