@@ -280,3 +280,67 @@ docker-compose pull
280
280
# Start a new container, automatically removes old one
281
281
docker-compose up -d
282
282
```
283
+
284
+ # SSH Container Passthrough
285
+
286
+ Since SSH is running inside the container, you'll have to pass SSH from the host to the
287
+ container if you wish to use SSH support. If you wish to do this without running the container
288
+ SSH on a non-standard port (or move your host port to a non-standard port) you can forward
289
+ SSH connections destined for the container with a little extra setup.
290
+
291
+ This guide assumes that you have created a user on the host called ` git ` which shares the same
292
+ UID/GID as the container values ` USER_UID ` /` USER_GID ` . You should also create the directory
293
+ ` /var/lib/gitea ` on the host, owned by the ` git ` user and mounted in the container, e.g.
294
+
295
+ ```
296
+ services:
297
+ server:
298
+ image: gitea/gitea:latest
299
+ environment:
300
+ - USER_UID=1000
301
+ - USER_GID=1000
302
+ restart: always
303
+ networks:
304
+ - gitea
305
+ volumes:
306
+ - /var/lib/gitea:/data
307
+ ports:
308
+ - "3000:3000"
309
+ - "127.0.0.1:2222:22"
310
+ ```
311
+
312
+ You can see that we're also exposing the container SSH port to port 2222 on the host, and binding this
313
+ to 127.0.0.1 to prevent it being accessible external to the host machine itself.
314
+
315
+ On the ** host** , you should create the file ` /app/gitea/gitea ` with the following contents and
316
+ make it executable (` chmod +x /app/gitea/gitea ` ):
317
+
318
+ ```
319
+ #!/bin/sh
320
+ ssh -p 2222 -o StrictHostKeyChecking=no [email protected] "SSH_ORIGINAL_COMMAND=\"$SSH_ORIGINAL_COMMAND\" $0 $@"
321
+ ```
322
+
323
+ Your ` git ` user needs to have an SSH key generated:
324
+
325
+ ```
326
+ sudo -u git ssh-keygen -t rsa -b 4096 -C "Gitea Host Key"
327
+ ```
328
+
329
+ Still on the host, symlink the container ` .ssh/authorized_keys ` file to your git user ` .ssh/authorized_keys ` .
330
+ This can be done on the host as the ` /var/lib/gitea ` directory is mounted inside the container under ` /data ` :
331
+
332
+ ```
333
+ ln -s /var/lib/gitea/git/.ssh/authorized_keys /home/git/.ssh/authorized_keys
334
+ ```
335
+
336
+ Then echo the ` git ` user SSH key into the authorized_keys file so the host can talk to the container over SSH:
337
+
338
+ ```
339
+ echo "no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty $(cat /home/git/.ssh/id_rsa.pub)" >> /var/lib/gitea/git/.ssh/authorized_keys
340
+ ```
341
+
342
+ Now you should be able to use Git over SSH to your container without disrupting SSH access to the host.
343
+
344
+ Please note: SSH container passthrough will work only if using opensshd in container, and will not work if
345
+ ` AuthorizedKeysCommand ` is used in combination with setting ` SSH_CREATE_AUTHORIZED_KEYS_FILE=false ` to disable
346
+ authorized files key generation.
0 commit comments