Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sshd_config - make 'Port' config key overridable using an env var #382

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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"]
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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@<host-ip>`
Expand Down
3 changes: 3 additions & 0 deletions files/entrypoint
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions files/sshd_config
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,5 @@ ChrootDirectory %h

# Enable this for more logs
#LogLevel VERBOSE

Port SSHD_PORT