Skip to content

Instantly share code, notes, and snippets.

@snigdhasjg
Created December 9, 2023 18:28
Show Gist options
  • Save snigdhasjg/4038c0cecdcecab5ad9a6f5b01b9f8f8 to your computer and use it in GitHub Desktop.
Save snigdhasjg/4038c0cecdcecab5ad9a6f5b01b9f8f8 to your computer and use it in GitHub Desktop.
git local server
no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty ssh-rsa AAAA<rsa-key> snigdhajyotighosh@Snigdhajyotis-MacBook-Pro.local
# Location ~/.ssh/config
Host localhost
Port 8022
Hostname localhost
IdentityFile ~/.ssh/id_rsa_common
UserKnownHostsFile /dev/null
StrictHostKeyChecking no
version: '3.9'
services:
git:
container_name: git
build:
context: .
ports:
- "8022:22"
volumes:
- git_repo:/home/git/repositories
volumes:
git_repo:
# Use the official Ubuntu image as the base image
FROM ubuntu:22.04
# Install OpenSSH server
RUN apt update && apt install -y openssh-server git
# Create an app user with git-shell
RUN useradd -ms /bin/bash -s $(which git-shell) git
# Switch as git user
USER git
WORKDIR /home/git
# Enable SSH public key-based authentication
RUN mkdir -m 700 .ssh git-shell-commands
COPY --chown=git:git --chmod=600 ./authorized_keys .ssh/
RUN mkdir -p repositories/project.git
RUN cd repositories/project.git && \
git config --global init.defaultBranch main && \
git init --bare
# Switch back to root user
USER root
WORKDIR /var/run/sshd
# Expose SSH port
EXPOSE 22
# Start SSH server
CMD ["/usr/sbin/sshd", "-D"]
git clone git@localhost:/git/project2/.git
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment