Skip to content

Commit c7785bf

Browse files
committed
Merge branch 'belsander/master'
2 parents 243e08b + 24aa2ef commit c7785bf

File tree

6 files changed

+29
-2
lines changed

6 files changed

+29
-2
lines changed

Dockerfile

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
FROM alpine:latest
22

33
LABEL org.opencontainers.image.authors="Oliver Filla <https://github.com/ofilla>, Carlos Bernárdez <carlos@z4studios.com>"
4+
LABEL maintainer='Carlos Bernárdez <carlos@z4studios.com>'
45

56
RUN apk add --no-cache openssh git
67

78
# -D flag avoids password generation
89
# -s flag changes user's shell
910
RUN adduser -D -s /usr/bin/git-shell git \
1011
&& passwd -u git \
11-
&& mkdir -p /git-server/keys /git-server/repos ~git/.ssh
12+
&& mkdir -p /git-server/keys /git-server/repos /opt/etc/ssh ~git/.ssh
13+
14+
WORKDIR /git-server/
15+
1216

1317
# This is a login shell for SSH accounts to provide restricted Git access.
1418
# It permits execution only of server-side Git commands implementing the
@@ -23,4 +27,5 @@ COPY start.sh start.sh
2327

2428
EXPOSE 22
2529

30+
VOLUME ["/git-server/keys", "/opt/etc/ssh", "/git-server/repos"]
2631
CMD ["sh", "start.sh"]

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ $ git clone ssh://git@<ip-docker-server>:2222/git-server/repos/myrepo.git
6363
* **Volumes**:
6464
* `/git-server/keys`: Volume to store the users public keys
6565
* `/git-server/repos`: Volume to store the repositories
66+
* `/git-server/host-keys`: Volume to store the SSHd host keys
6667

6768
### SSH Keys
6869

docker-compose.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,8 @@ services:
99
volumes:
1010
- ${GIT_SERVER_KEYS_DIR:-~/git-server/keys}:/git-server/keys:ro
1111
- ${GIT_SERVER_REPO_DIR:-~/git-server/repos}:/git-server/repos
12+
- host_keys:/opt/etc/ssh
1213

14+
volumes:
15+
host_keys:
16+
name: git-server-host-keys

git-shell-commands/no-interactive-login

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,16 @@
22
printf '%s\n' "Welcome to git-server-docker!"
33
printf '%s\n' "You've successfully authenticated, but I do not"
44
printf '%s\n' "provide interactive shell access."
5+
6+
printf '\n'
7+
printf '%s\n' "The following repositories are available:"
8+
for REPO in /git-server/repos/*
9+
do
10+
printf '%s\n' " - $(basename ${REPO%.git})"
11+
done
12+
13+
printf '\n'
14+
printf '%s\n' "To clone, use the following URL:"
15+
printf '%s\n' "ssh://git@<SERVER>:<PORT>/git-server/repos/<REPO_NAME>.git"
16+
517
exit 128

sshd_config

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,8 @@ AllowUsers git
77
X11Forwarding no
88
AllowTcpForwarding no
99
PermitTTY no
10+
11+
# host keys at different path
12+
HostKey /opt/etc/ssh/ssh_host_rsa_key
13+
HostKey /opt/etc/ssh/ssh_host_ecdsa_key
14+
HostKey /opt/etc/ssh/ssh_host_ed25519_key

start.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ _term() {
88
trap _term SIGTERM
99

1010
# generate host keys, if required
11-
ssh-keygen -A
11+
ssh-keygen -A -f /opt
1212

1313
# If there are some public keys in keys folder
1414
# then it copies its contain in authorized_keys file

0 commit comments

Comments
 (0)